Bug 971276 - Hitting enter should insert the currently selected item from an autocomplete list in the Style Editor, r=harth

This commit is contained in:
Girish Sharma 2014-02-16 13:56:26 +05:30
Родитель 147388c3e8
Коммит a7fd58cdc5
2 изменённых файлов: 30 добавлений и 29 удалений

Просмотреть файл

@ -28,39 +28,34 @@ function setupAutoCompletion(ctx, walker) {
autoSelect: true
});
let cycle = (reverse) => {
if (popup && popup.isOpen) {
cycleSuggestions(ed, reverse == true);
return;
}
return win.CodeMirror.Pass;
};
let keyMap = {
"Tab": cm => {
"Tab": cycle,
"Down": cycle,
"Shift-Tab": cycle.bind(this, true),
"Up": cycle.bind(this, true),
"Enter": () => {
if (popup && popup.isOpen) {
cycleSuggestions(ed);
if (!privates.get(ed).suggestionInsertedOnce) {
privates.get(ed).insertingSuggestion = true;
let {label, preLabel} = popup.getItemAtIndex(0);
let cur = ed.getCursor();
ed.replaceText(label.slice(preLabel.length), cur, cur);
}
popup.hidePopup();
return;
}
return win.CodeMirror.Pass;
},
"Shift-Tab": cm => {
if (popup && popup.isOpen) {
cycleSuggestions(ed, true);
return;
}
return win.CodeMirror.Pass;
},
"Up": cm => {
if (popup && popup.isOpen) {
cycleSuggestions(ed, true);
return;
}
return win.CodeMirror.Pass;
},
"Down": cm => {
if (popup && popup.isOpen) {
cycleSuggestions(ed);
return;
}
return win.CodeMirror.Pass;
},
}
};
keyMap[Editor.accel("Space")] = cm => autoComplete(ctx);
cm.addKeyMap(keyMap);
@ -172,7 +167,6 @@ function onEditorKeypress(ed, event) {
case event.DOM_VK_END:
case event.DOM_VK_BACK_SPACE:
case event.DOM_VK_DELETE:
case event.DOM_VK_RETURN:
private.doNotAutocomplete = true;
private.popup.hidePopup();
break;

Просмотреть файл

@ -49,7 +49,7 @@ let TEST_CASES = [
['VK_RETURN', -1],
['b', 2, 0],
['u', 1, 0],
['VK_TAB', -1],
['VK_RETURN', -1, 0, 1],
['{', -1],
['VK_HOME', -1],
['VK_DOWN', -1],
@ -147,6 +147,13 @@ function checkState() {
}
else {
ok(!gPopup.isOpen, "Popup is closed for index " + index);
if (inserted) {
let { preLabel, label } = gPopup.getItemAtIndex(current);
let { line, ch } = gEditor.getCursor();
let lineText = gEditor.getText(line);
is(lineText.substring(ch - label.length, ch), label,
"Current suggestion from the popup is inserted into the editor.");
}
}
index++;
testState();