зеркало из https://github.com/mozilla/gecko-dev.git
Bug 913955 - Avoid race conditions and inserting in middle of text in inplace-editor, r=mratcliffe
This commit is contained in:
Родитель
234e097ae9
Коммит
716b40c176
|
@ -1008,6 +1008,11 @@ InplaceEditor.prototype = {
|
|||
* true if you don't want to automatically insert the first suggestion
|
||||
*/
|
||||
_maybeSuggestCompletion: function(aNoAutoInsert) {
|
||||
// Input can be null in cases when you intantaneously switch out of it.
|
||||
if (!this.input) {
|
||||
return;
|
||||
}
|
||||
let preTimeoutQuery = this.input.value;
|
||||
// Since we are calling this method from a keypress event handler, the
|
||||
// |input.value| does not include currently typed character. Thus we perform
|
||||
// this method async.
|
||||
|
@ -1019,10 +1024,12 @@ InplaceEditor.prototype = {
|
|||
if (this.contentType == CONTENT_TYPES.PLAIN_TEXT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.input) {
|
||||
return;
|
||||
}
|
||||
let input = this.input;
|
||||
// Input can be null in cases when you intantaneously switch out of it.
|
||||
if (!input) {
|
||||
// The length of input.value should be increased by 1
|
||||
if (input.value.length - preTimeoutQuery.length > 1) {
|
||||
return;
|
||||
}
|
||||
let query = input.value.slice(0, input.selectionStart);
|
||||
|
@ -1030,6 +1037,15 @@ InplaceEditor.prototype = {
|
|||
if (query == null) {
|
||||
return;
|
||||
}
|
||||
// If nothing is selected and there is a non-space character after the
|
||||
// cursor, do not autocomplete.
|
||||
if (input.selectionStart == input.selectionEnd &&
|
||||
input.selectionStart < input.value.length &&
|
||||
input.value.slice(input.selectionStart)[0] != " ") {
|
||||
// This emit is mainly to make the test flow simpler.
|
||||
this.emit("after-suggest", "nothing to autocomplete");
|
||||
return;
|
||||
}
|
||||
let list = [];
|
||||
if (this.contentType == CONTENT_TYPES.CSS_PROPERTY) {
|
||||
list = CSSPropertyList;
|
||||
|
|
|
@ -48,6 +48,9 @@ let testData = [
|
|||
["VK_BACK_SPACE", "", -1, 0],
|
||||
["f", "fill", 0, MAX_ENTRIES],
|
||||
["i", "fill", 0, 4],
|
||||
["VK_LEFT", "fill", -1, 0],
|
||||
["VK_LEFT", "fill", -1, 0],
|
||||
["i", "fiill", -1, 0],
|
||||
["VK_ESCAPE", null, -1, 0],
|
||||
];
|
||||
|
||||
|
@ -90,7 +93,7 @@ function checkStateAndMoveOn(index) {
|
|||
|
||||
info("pressing key " + key + " to get result: [" + testData[index].slice(1) +
|
||||
"] for state " + state);
|
||||
if (/(right|back_space|escape)/ig.test(key)) {
|
||||
if (/(left|right|back_space|escape)/ig.test(key)) {
|
||||
info("added event listener for right|back_space|escape keys");
|
||||
editor.input.addEventListener("keypress", function onKeypress() {
|
||||
if (editor.input) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче