From f9b3655c943dee63b7aba01610bd1ee1d88e6878 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 2 Jul 2014 22:24:20 +0400 Subject: [PATCH 1/3] fix autocomplete popup click regression --- lib/ace/autocomplete/popup.js | 1 + lib/ace/keyboard/textinput.js | 14 +++++++++----- lib/ace/mouse/mouse_handler.js | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index a0ab7604..c8d168a6 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -67,6 +67,7 @@ var AcePopup = function(parentNode) { popup.renderer.setStyle("ace_autocomplete"); popup.setOption("displayIndentGuides", false); + popup.setOption("dragDelay", 150); var noop = function(){}; diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index fbf37786..ed213d70 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -428,13 +428,17 @@ var TextInput = function(parentNode, host) { this.onContextMenu = function(e) { afterContextMenu = true; - if (!tempStyle) - tempStyle = text.style.cssText; - - text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : ""); - resetSelection(host.selection.isEmpty()); host._emit("nativecontextmenu", {target: host, domEvent: e}); + this.moveToMouse(e, true); + }; + + this.moveToMouse = function(e, bringToFront) { + if (!tempStyle) + tempStyle = text.style.cssText; + text.style.cssText = (bringToFront ? "z-index:100000;" : "") + + (useragent.isIE ? "opacity:0.1;" : ""); + var rect = host.container.getBoundingClientRect(); var style = dom.computedStyle(host.container); var top = rect.top + (parseInt(style.borderTopWidth) || 0); diff --git a/lib/ace/mouse/mouse_handler.js b/lib/ace/mouse/mouse_handler.js index ce88eb81..9cf26721 100644 --- a/lib/ace/mouse/mouse_handler.js +++ b/lib/ace/mouse/mouse_handler.js @@ -49,7 +49,7 @@ var MouseHandler = function(editor) { var focusEditor = function(e) { if (!editor.isFocused() && editor.textInput) - editor.textInput.onContextMenu(e); + editor.textInput.moveToMouse(e); editor.focus() }; From f8be5072ac0d3ea6befade28a53c4e4c8fbbab96 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 2 Jul 2014 23:56:24 +0400 Subject: [PATCH 2/3] allow using name instead of caption --- lib/ace/autocomplete/popup.js | 2 +- lib/ace/autocomplete/text_completer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ace/autocomplete/popup.js b/lib/ace/autocomplete/popup.js index c8d168a6..a34ebf09 100644 --- a/lib/ace/autocomplete/popup.js +++ b/lib/ace/autocomplete/popup.js @@ -179,7 +179,7 @@ var AcePopup = function(parentNode) { if (typeof data == "string") data = {value: data}; if (!data.caption) - data.caption = data.value; + data.caption = data.value || data.name; var last = -1; var flag, c; diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index 6eebfc61..17a4bdad 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -68,7 +68,7 @@ define(function(require, exports, module) { var wordList = Object.keys(wordScore); callback(null, wordList.map(function(word) { return { - name: word, + caption: word, value: word, score: wordScore[word], meta: "local" From 8ed27996207ed25e1e0a4b9ce7394b805ee7ce40 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 3 Jul 2014 00:12:27 +0400 Subject: [PATCH 3/3] do not close the popup if there are matching completions --- lib/ace/autocomplete.js | 13 ++++++------- lib/ace/ext/language_tools.js | 4 ---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index adf9bd73..13d140d9 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -101,12 +101,12 @@ var Autocomplete = function() { this.changeTimer.cancel(); if (this.popup && this.popup.isOpen) { - this.gatherCompletionsId = this.gatherCompletionsId + 1; - } - - if (this.popup) + this.gatherCompletionsId += 1; this.popup.hide(); - + } + + if (this.base) + this.base.detach(); this.activated = false; this.completions = this.base = null; }; @@ -205,8 +205,7 @@ var Autocomplete = function() { var line = session.getLine(pos.row); var prefix = util.retrievePrecedingIdentifier(line, pos.column); - this.base = editor.getCursorPosition(); - this.base.column -= prefix.length; + this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length); var matches = []; var total = editor.completers.length; diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index dc56e6e0..d8b2a1dd 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -161,10 +161,6 @@ var doLiveAutocomplete = function(e) { editor.completer.autoSelect = false; editor.completer.autoInsert = false; editor.completer.showPopup(editor); - } else if (!prefix && hasCompleter) { - // When the prefix is empty - // close the autocomplete dialog - editor.completer.detach(); } } };