Don't get confused by commands in arguments in autocomplete

This commit is contained in:
James Allen 2017-09-05 19:26:13 +02:00
parent 8a612df009
commit b2257db2c2
2 changed files with 18 additions and 6 deletions

View file

@ -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)

View file

@ -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]