1. The underlying textarea now listens to "input" event, and update the content of target morphic

accordingly.
2. The textarea still listens to "keydown" and "keyup" events, for the following puerpose:
"keydown" event handler will detech some system shortcuts, add will pass it to "the world".
"keyup" event handler is used to capture the change of selection status and cursor position of the
textarea (which is not captured in the above "input" event), and update the target morphic.
pull/89/head
Zhenlei Jia 2019-07-11 08:38:51 -04:00
rodzic e972ae0ccd
commit d8e2bc3129
1 zmienionych plików z 25 dodań i 2 usunięć

Wyświetl plik

@ -5421,7 +5421,7 @@ CursorMorph.prototype.initializeTextarea = function () {
// For other keyboard events, first let the textarea element handle the
// events, then we take its state and update the target morph and cursor
// morph accordingly.
this.textarea.addEventListener('keyup', function (event) {
this.textarea.addEventListener('input', function (event) {
myself.world().currentKey = null;
var target = myself.target;
@ -5461,6 +5461,7 @@ CursorMorph.prototype.initializeTextarea = function () {
}
// target morph: copy the content and selection status to the target.
target.text = filteredContent;
if (textarea.selectionStart === textarea.selectionEnd) {
target.startMark = null;
target.endMark = null;
@ -5481,7 +5482,29 @@ CursorMorph.prototype.initializeTextarea = function () {
myself.gotoSlot(textarea.selectionStart);
myself.updateTextAreaPosition();
target.escalateEvent('reactToKeystroke', event);
//target.escalateEvent('reactToKeystroke', event);
});
this.textarea.addEventListener('keyup', function (event) {
var textarea = myself.textarea;
var target = myself.target;
if (textarea.selectionStart === textarea.selectionEnd) {
target.startMark = null;
target.endMark = null;
} else {
if (textarea.selectionDirection === 'backward') {
target.startMark = textarea.selectionEnd;
target.endMark = textarea.selectionStart;
} else {
target.startMark = textarea.selectionStart;
target.endMark = textarea.selectionEnd;
}
}
target.changed();
target.drawNew();
target.changed();
myself.gotoSlot(textarea.selectionEnd);
});
};