mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add a '}' at the end of citation autocomplete if required.
This commit is contained in:
parent
2d4ced6a1c
commit
cff00c09b0
1 changed files with 10 additions and 7 deletions
|
@ -45,12 +45,15 @@ define [
|
||||||
references = @$scope.$root._references
|
references = @$scope.$root._references
|
||||||
ReferencesCompleter =
|
ReferencesCompleter =
|
||||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||||
range = new Range(pos.row, 0, pos.row, pos.column)
|
upToCursorRange = new Range(pos.row, 0, pos.row, pos.column)
|
||||||
lineUpToCursor = editor.getSession().getTextRange(range)
|
lineUpToCursor = editor.getSession().getTextRange(upToCursorRange)
|
||||||
commandFragment = getLastCommandFragment(lineUpToCursor)
|
commandFragment = getLastCommandFragment(lineUpToCursor)
|
||||||
if commandFragment
|
if commandFragment
|
||||||
citeMatch = commandFragment.match(/^~?\\([a-z]*cite[a-z]?){(.*,)?(\w*)/)
|
citeMatch = commandFragment.match(/^~?\\([a-z]*cite[a-z]?){([^}]*,)?(\w*)/)
|
||||||
if citeMatch
|
if citeMatch
|
||||||
|
beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999)
|
||||||
|
lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
|
||||||
|
needsClosingBrace = !lineBeyondCursor.match(/\w*}/)
|
||||||
commandName = citeMatch[1]
|
commandName = citeMatch[1]
|
||||||
previousArgs = citeMatch[2]
|
previousArgs = citeMatch[2]
|
||||||
currentArg = citeMatch[3]
|
currentArg = citeMatch[3]
|
||||||
|
@ -59,8 +62,8 @@ define [
|
||||||
previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs
|
previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs
|
||||||
result = []
|
result = []
|
||||||
result.push {
|
result.push {
|
||||||
caption: "\\#{commandName}{",
|
caption: "\\#{commandName}{}",
|
||||||
snippet: "\\#{commandName}{",
|
snippet: "\\#{commandName}{}",
|
||||||
meta: "reference",
|
meta: "reference",
|
||||||
score: 11000
|
score: 11000
|
||||||
}
|
}
|
||||||
|
@ -68,8 +71,8 @@ define [
|
||||||
references.keys.forEach (key) ->
|
references.keys.forEach (key) ->
|
||||||
if !(key in [null, undefined])
|
if !(key in [null, undefined])
|
||||||
result.push({
|
result.push({
|
||||||
caption: "\\#{commandName}{#{previousArgsCaption}#{key}",
|
caption: "\\#{commandName}{#{previousArgsCaption}#{key}#{if needsClosingBrace then '}' else ''}",
|
||||||
value: "\\#{commandName}{#{previousArgs}#{key}",
|
value: "\\#{commandName}{#{previousArgs}#{key}#{if needsClosingBrace then '}' else ''}",
|
||||||
meta: "reference",
|
meta: "reference",
|
||||||
score: 10000
|
score: 10000
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue