Safeguard against wacky keys for now

Change-Id: I48e8a5a6bbf66a11c71d676e11b3d5f7c84cb29d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/407456
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-05-12 11:23:40 -04:00
parent cc29ca5196
commit 433d25c947
2 changed files with 7 additions and 4 deletions

View File

@ -126,8 +126,10 @@ canvas {
} }
} }
if (!e.ctrlKey && !e.metaKey) { if (!e.ctrlKey && !e.metaKey) {
e.preventDefault(); // at least needed for 'space' if (e.key.length == 1) { // avoid keys like "Escape" for now
editor.insert(e.key); e.preventDefault();
editor.insert(e.key);
}
} }
} }

View File

@ -381,6 +381,7 @@ function MakeEditor(text, style, cursor, width) {
this._buildLines(); this._buildLines();
}, },
insert: function(charcode) { insert: function(charcode) {
const len = charcode.length;
if (this._index.start != this._index.end) { if (this._index.start != this._index.end) {
this.deleteSelection(); this.deleteSelection();
} }
@ -388,12 +389,12 @@ function MakeEditor(text, style, cursor, width) {
// do this before edit the text (we use text.length in an assert) // do this before edit the text (we use text.length in an assert)
const [i, prev_len] = this.find_style_index_and_prev_length(index); const [i, prev_len] = this.find_style_index_and_prev_length(index);
this._styles[i]._length += 1; this._styles[i]._length += len;
// now grow the text // now grow the text
this._text = this._text.slice(0, index) + charcode + this._text.slice(index); this._text = this._text.slice(0, index) + charcode + this._text.slice(index);
this._index.start = this._index.end = index + 1; this._index.start = this._index.end = index + len;
this._buildLines(); this._buildLines();
}, },