Bug 985924 - Upgrade autocomplete to support multi selection in CodeMirror 4; r=msucan

This commit is contained in:
Brian Grinstead 2014-04-01 09:59:00 -05:00
Родитель a271a41081
Коммит 9f150cc40f
2 изменённых файлов: 19 добавлений и 1 удалений

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

@ -103,10 +103,12 @@ function autoComplete({ ed, cm }) {
// "backgr|" but we need to open the popup at the beginning of the character
// "b". Thus we need to calculate the width of the entered part of the token
// ("backgr" here). 4 comes from the popup's left padding.
let cursorElement = cm.display.cursorDiv.querySelector(".CodeMirror-cursor");
let left = suggestions[0].preLabel.length * cm.defaultCharWidth() + 4;
popup.hidePopup();
popup.setItems(suggestions);
popup.openPopup(cm.display.cursor, -1 * left, 0);
popup.openPopup(cursorElement, -1 * left, 0);
private.suggestionInsertedOnce = false;
// This event is used in tests.
ed.emit("after-suggest");
@ -159,6 +161,14 @@ function cycleSuggestions(ed, reverse) {
*/
function onEditorKeypress({ ed, Editor }, event) {
let private = privates.get(ed);
// Do not try to autocomplete with multiple selections.
if (ed.hasMultipleSelections()) {
private.doNotAutocomplete = true;
private.popup.hidePopup();
return;
}
switch (event.keyCode) {
case event.DOM_VK_ESCAPE:
if (private.popup.isOpen)

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

@ -403,6 +403,14 @@ Editor.prototype = {
this.setCursor(this.getCursor());
},
/**
* Returns true if there is more than one selection in the editor.
*/
hasMultipleSelections: function () {
let cm = editors.get(this);
return cm.listSelections().length > 1;
},
/**
* Gets the first visible line number in the editor.
*/