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: () ->