Remove trailing } when autocompleting from within a \begin{...} command

This commit is contained in:
James Allen 2014-03-27 15:51:19 +00:00
parent e1a130a941
commit 544415ce1d

View file

@ -2,10 +2,12 @@ define [
"auto-complete/SuggestionManager" "auto-complete/SuggestionManager"
"auto-complete/Snippets" "auto-complete/Snippets"
"ace/autocomplete/util" "ace/autocomplete/util"
"ace/autocomplete"
"ace/range" "ace/range"
"ace/ext/language_tools" "ace/ext/language_tools"
], (SuggestionManager, Snippets, Util) -> ], (SuggestionManager, Snippets, Util, AutoComplete) ->
Range = require("ace/range").Range Range = require("ace/range").Range
Autocomplete = AutoComplete.Autocomplete
Util.retrievePrecedingIdentifier = (text, pos, regex) -> Util.retrievePrecedingIdentifier = (text, pos, regex) ->
currentLineOffset = 0 currentLineOffset = 0
@ -38,6 +40,20 @@ define [
@aceEditor.completers = [@suggestionManager, SnippetCompleter] @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()
bindToEditorEvents: () -> bindToEditorEvents: () ->