From 544415ce1d5f869fa4137807a3194b54a7ee519b Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 27 Mar 2014 15:51:19 +0000 Subject: [PATCH] Remove trailing } when autocompleting from within a \begin{...} command --- .../auto-complete/AutoCompleteManager.coffee | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/auto-complete/AutoCompleteManager.coffee index bbed4b87f9..52ae4a6b49 100644 --- a/services/web/public/coffee/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/auto-complete/AutoCompleteManager.coffee @@ -2,10 +2,12 @@ define [ "auto-complete/SuggestionManager" "auto-complete/Snippets" "ace/autocomplete/util" + "ace/autocomplete" "ace/range" "ace/ext/language_tools" -], (SuggestionManager, Snippets, Util) -> +], (SuggestionManager, Snippets, Util, AutoComplete) -> Range = require("ace/range").Range + Autocomplete = AutoComplete.Autocomplete Util.retrievePrecedingIdentifier = (text, pos, regex) -> currentLineOffset = 0 @@ -38,6 +40,20 @@ define [ @aceEditor.completers = [@suggestionManager, SnippetCompleter] + insertMatch = Autocomplete::insertMatch + editor = @aceEditor + Autocomplete::insertMatch = (data) -> + pos = editor.getCursorPosition() + range = new Range(pos.row, pos.column, pos.row, pos.column + 1) + nextChar = editor.session.getTextRange(range) + + # If we are in \begin{it|}, then we need to remove the trailing } + # since it will be adding in with the autocomplete of \begin{item}... + if this.completions.filterText.match(/^\\begin\{/) and nextChar == "}" + editor.session.remove(range) + + insertMatch.call editor.completer, data + @bindToEditorEvents() bindToEditorEvents: () ->