mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Don't get confused by commands in arguments in autocomplete
This commit is contained in:
parent
8a612df009
commit
b2257db2c2
2 changed files with 18 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in a new issue