minor code reformatting for LINTers

pull/89/head
jmoenig 2019-07-23 08:00:07 +02:00
rodzic 159196113e
commit 3d3e098103
3 zmienionych plików z 65 dodań i 53 usunięć

Wyświetl plik

@ -6,6 +6,9 @@
* **Notable Fixes:** * **Notable Fixes:**
* **Translation Updates:** * **Translation Updates:**
### 2019-07-23
* morphic: minor code reformatting for LINTers
### 2019-07-22 ### 2019-07-22
* new dev version * new dev version
* morphic, blocks: support for enhanced character set keyboard input, thanks, @swiperthefox! * morphic, blocks: support for enhanced character set keyboard input, thanks, @swiperthefox!

Wyświetl plik

@ -4,7 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Snap! Build Your Own Blocks 5.0.6 - dev -</title> <title>Snap! Build Your Own Blocks 5.0.6 - dev -</title>
<link rel="shortcut icon" href="src/favicon.ico"> <link rel="shortcut icon" href="src/favicon.ico">
<script type="text/javascript" src="src/morphic.js?version=2019-07-22"></script> <script type="text/javascript" src="src/morphic.js?version=2019-07-23"></script>
<script type="text/javascript" src="src/widgets.js?version=2019-06-27"></script> <script type="text/javascript" src="src/widgets.js?version=2019-06-27"></script>
<script type="text/javascript" src="src/blocks.js?version=2019-07-22"></script> <script type="text/javascript" src="src/blocks.js?version=2019-07-22"></script>
<script type="text/javascript" src="src/threads.js?version=2019-07-15"></script> <script type="text/javascript" src="src/threads.js?version=2019-07-15"></script>

Wyświetl plik

@ -1162,7 +1162,7 @@
/*global window, HTMLCanvasElement, FileReader, Audio, FileList, Map*/ /*global window, HTMLCanvasElement, FileReader, Audio, FileList, Map*/
var morphicVersion = '2019-July-22'; var morphicVersion = '2019-July-23';
var modules = {}; // keep track of additional loaded modules var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@ -5370,7 +5370,11 @@ CursorMorph.prototype.init = function (aStringOrTextMorph) {
this.originalContents = this.target.text; this.originalContents = this.target.text;
this.originalAlignment = this.target.alignment; this.originalAlignment = this.target.alignment;
this.slot = this.target.text.length; this.slot = this.target.text.length;
this.textarea = null;
CursorMorph.uber.init.call(this); CursorMorph.uber.init.call(this);
// override inherited defaults
ls = fontHeight(this.target.fontSize); ls = fontHeight(this.target.fontSize);
this.setExtent(new Point(Math.max(Math.floor(ls / 20), 1), ls)); this.setExtent(new Point(Math.max(Math.floor(ls / 20), 1), ls));
this.drawNew(); this.drawNew();
@ -5399,39 +5403,39 @@ CursorMorph.prototype.initializeTextarea = function () {
this.syncTextareaSelectionWith(this.target); this.syncTextareaSelectionWith(this.target);
/** /*
* There are three cases when the textarea get some inputs: There are three cases when the textarea gets inputs:
*
* 1. The inputs represents special shortcuts of Snap! system, so we 1. Inputs that represent special shortcuts of Snap!, so we
* don't want the textarea to handle it. These events are captured in don't want the textarea to handle it. These events are captured in
* "keydown" event handler. "keydown" event handler.
*
* 2. The inputs changed the content of the textarea, we need to update 2. inputs that change the content of the textarea, we need to update
* the content of its target morphic accordingly. This is handled in the content of its target morph accordingly. This is handled in
* the "input" event handler. the "input" event handler.
*
* 3. The input causes changes on the textarea, but the change will not 3. input that change the textarea without triggering an "input" event,
* trigger and "input" event (such changes include selection change, cursor e.g. selection change, cursor movements. These are handled in the
* movements). These are handled in "keyup" event handler. "keyup" event handler.
*
* Note that some changes in case 2 are not caused by keyboards (for example, Note that some changes in case 2 are not caused by keyboards (for
* select a word by clicking in IME window), so there are overlaps between example, select a word by clicking in IME window), so there are overlaps
* case 2 and case 3. but no one can replace the other. between case 2 and case 3. but no one can replace the other.
*/ */
this.textarea.addEventListener('keydown', function (event) {
/* Special shortcuts for Snap! system. /* Special shortcuts for Snap! system.
- ctrl-d, ctrl-i and ctrl-p: doit, inspect it and print it - ctrl-d, ctrl-i and ctrl-p: doit, inspect it and print it
- tab: goto next text field - tab: goto next text field
- esc: discard the editing - esc: discard the editing
- enter / shift+enter: accept the editing - enter / shift+enter: accept the editing
*/ */
this.textarea.addEventListener('keydown', function (event) { var keyName = event.key,
// other part of the world need to know the current key shift = event.shiftKey,
myself.world().currentKey = event.keyCode; singleLineText = myself.target instanceof StringMorph;
var keyName = event.key; // other parts of the world need to know the current key
var shift = event.shiftKey; myself.world().currentKey = event.keyCode;
var singleLineText = myself.target instanceof StringMorph;
if (!isNil(myself.target.receiver) && if (!isNil(myself.target.receiver) &&
(event.ctrlKey || event.metaKey)) { (event.ctrlKey || event.metaKey)) {
@ -5460,28 +5464,32 @@ CursorMorph.prototype.initializeTextarea = function () {
} }
}); });
// handle content change.
this.textarea.addEventListener('input', function (event) { this.textarea.addEventListener('input', function (event) {
myself.world().currentKey = null; // handle content change.
var target = myself.target,
textarea = myself.textarea,
filteredContent,
caret;
var target = myself.target; myself.world().currentKey = null;
var textarea = myself.textarea;
var filteredContent;
// filter invalid chars for numeric fields // filter invalid chars for numeric fields
function filterText (content) { function filterText (content) {
var points = 0; var points = 0,
var result = ''; result = '',
for (var i=0; i < content.length; i++) { i, ch, valid;
var ch = content.charAt(i); for (i = 0; i < content.length; i += 1) {
var valid = ( ch = content.charAt(i);
valid = (
('0' <= ch && ch <= '9') || // digits ('0' <= ch && ch <= '9') || // digits
(i === 0 && ch === '-') || // leading '-' (i === 0 && ch === '-') || // leading '-'
(ch === '.' && points === 0) // at most '.' (ch === '.' && points === 0) // at most '.'
); );
if (valid) { if (valid) {
result += ch; result += ch;
if (ch === '.') points++; if (ch === '.') {
points += 1;
}
} }
} }
return result; return result;
@ -5495,7 +5503,7 @@ CursorMorph.prototype.initializeTextarea = function () {
if (filteredContent.length < textarea.value.length) { if (filteredContent.length < textarea.value.length) {
textarea.value = filteredContent; textarea.value = filteredContent;
var caret = Math.min(textarea.selectionStart, filteredContent.length); caret = Math.min(textarea.selectionStart, filteredContent.length);
textarea.selectionEnd = caret; textarea.selectionEnd = caret;
textarea.selectionStart = caret; textarea.selectionStart = caret;
} }
@ -5524,11 +5532,10 @@ CursorMorph.prototype.initializeTextarea = function () {
myself.updateTextAreaPosition(); myself.updateTextAreaPosition();
}); });
// handle selection change and cursor position change.
this.textarea.addEventListener('keyup', function (event) { this.textarea.addEventListener('keyup', function (event) {
var textarea = myself.textarea; // handle selection change and cursor position change.
var target = myself.target; var textarea = myself.textarea,
target = myself.target;
if (textarea.selectionStart === textarea.selectionEnd) { if (textarea.selectionStart === textarea.selectionEnd) {
target.startMark = null; target.startMark = null;
@ -5550,17 +5557,19 @@ CursorMorph.prototype.initializeTextarea = function () {
}; };
CursorMorph.prototype.updateTextAreaPosition = function () { CursorMorph.prototype.updateTextAreaPosition = function () {
var origin = this.target.bounds.origin;
function number2px (n) { function number2px (n) {
return Math.ceil(n) + 'px'; return Math.ceil(n) + 'px';
} }
var origin = this.target.bounds.origin;
this.textarea.style.top = number2px(origin.y); this.textarea.style.top = number2px(origin.y);
this.textarea.style.left = number2px(origin.x); this.textarea.style.left = number2px(origin.x);
}; };
CursorMorph.prototype.syncTextareaSelectionWith = function (targetMorph) { CursorMorph.prototype.syncTextareaSelectionWith = function (targetMorph) {
var start = targetMorph.startMark; var start = targetMorph.startMark,
var end = targetMorph.endMark; end = targetMorph.endMark;
if (start === end) { if (start === end) {
this.textarea.setSelectionRange(this.slot, this.slot, 'none'); this.textarea.setSelectionRange(this.slot, this.slot, 'none');