From b2257db2c2ab67eeca9aba15b3397d412b503187 Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 5 Sep 2017 19:26:13 +0200 Subject: [PATCH] Don't get confused by commands in arguments in autocomplete --- .../auto-complete/AutoCompleteManager.coffee | 8 ++++---- .../aceEditor/auto-complete/Helpers.coffee | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index e760264191..24a524b4b6 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -213,10 +213,10 @@ define [ range.start.column, ) ) - # Delete back to last backslash, as appropriate - lastBackslashIndex = lineUpToCursor.lastIndexOf('\\') - if lastBackslashIndex != -1 - leftRange.start.column = lastBackslashIndex + # Delete back to command start, as appropriate + commandStartIndex = Helpers.getLastCommandFragmentIndex(lineUpToCursor) + if commandStartIndex != -1 + leftRange.start.column = commandStartIndex else leftRange.start.column -= completions.filterText.length editor.session.remove(leftRange) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee index 2744d1fa29..7beb41debd 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee @@ -6,11 +6,23 @@ define [ Helpers = getLastCommandFragment: (lineUpToCursor) -> - if m = lineUpToCursor.match(/(\\[^\\]+)$/) - return m[1] + if (index = Helpers.getLastCommandFragmentIndex(lineUpToCursor)) > -1 + return lineUpToCursor.slice(index) else return null + getLastCommandFragmentIndex: (lineUpToCursor) -> + # This is hack to let us skip over commands in arguments, and + # go to the command on the same 'level' as us. E.g. + # \includegraphics[width=\textwidth]{.. + # should not match the \textwidth. + blankArguments = lineUpToCursor.replace /\[([^\]]*)\]/g, (args) -> + Array(args.length+1).join('.') + if m = blankArguments.match(/(\\[^\\]+)$/) + return m.index + else + return -1 + getCommandNameFromFragment: (commandFragment) -> commandFragment?.match(/\\(\w+)\{/)?[1]