mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 12:21:04 +00: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,
|
range.start.column,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Delete back to last backslash, as appropriate
|
# Delete back to command start, as appropriate
|
||||||
lastBackslashIndex = lineUpToCursor.lastIndexOf('\\')
|
commandStartIndex = Helpers.getLastCommandFragmentIndex(lineUpToCursor)
|
||||||
if lastBackslashIndex != -1
|
if commandStartIndex != -1
|
||||||
leftRange.start.column = lastBackslashIndex
|
leftRange.start.column = commandStartIndex
|
||||||
else
|
else
|
||||||
leftRange.start.column -= completions.filterText.length
|
leftRange.start.column -= completions.filterText.length
|
||||||
editor.session.remove(leftRange)
|
editor.session.remove(leftRange)
|
||||||
|
|
|
@ -6,11 +6,23 @@ define [
|
||||||
|
|
||||||
Helpers =
|
Helpers =
|
||||||
getLastCommandFragment: (lineUpToCursor) ->
|
getLastCommandFragment: (lineUpToCursor) ->
|
||||||
if m = lineUpToCursor.match(/(\\[^\\]+)$/)
|
if (index = Helpers.getLastCommandFragmentIndex(lineUpToCursor)) > -1
|
||||||
return m[1]
|
return lineUpToCursor.slice(index)
|
||||||
else
|
else
|
||||||
return null
|
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) ->
|
getCommandNameFromFragment: (commandFragment) ->
|
||||||
commandFragment?.match(/\\(\w+)\{/)?[1]
|
commandFragment?.match(/\\(\w+)\{/)?[1]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue