From a7297de55f6da1f6f807d0cd374232edb9dace02 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sat, 5 Apr 2014 20:16:02 +0200 Subject: [PATCH] Update autocomplete to handle custom identifier regexprsw --- lib/ace/autocomplete.js | 7 ++----- lib/ace/ext/language_tools.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 6e064381..ccc50a4c 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -212,7 +212,7 @@ var Autocomplete = function() { var pos = editor.getCursorPosition(); var line = session.getLine(pos.row); callback(null, { - prefix: util.retrievePrecedingIdentifier(line, pos.column), + prefix: util.retrievePrecedingIdentifier(line, pos.column, results.length > 0 ? results[0].identifierRegex : undefined), matches: matches, finished: (--total === 0) }); @@ -270,10 +270,7 @@ var Autocomplete = function() { }.bind(this); // Calcul prefix - var session = this.editor.getSession(); - var pos = this.editor.getCursorPosition(); - var line = session.getLine(pos.row); - var prefix = util.retrievePrecedingIdentifier(line, pos.column); + var prefix = results.prefix; // Results matches var matches = results && results.matches; diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 6c1182a1..b6cc9d0d 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -122,7 +122,15 @@ var doLiveAutocomplete = function(e) { var line = editor.session.getLine(pos.row); var hasCompleter = editor.completer && editor.completer.activated; var prefix = util.retrievePrecedingIdentifier(line, pos.column); - + //Try to find custom prefixes on the completors + completers.forEach(function(completer){ + if(completer.identifierRegexprs){ + completer.identifierRegexprs.forEach(function(identifierRegex){ + prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex); + }); + } + }); + // We don't want to autocomplete with no prefix if (e.command.name === "backspace" && !prefix) { if (hasCompleter) @@ -185,4 +193,4 @@ require("../config").defineOptions(Editor.prototype, "editor", { } }); -}); \ No newline at end of file +});