Handle cite commands like citep and citet, etc.

This commit is contained in:
Shane Kilkelly 2016-02-03 15:08:52 +00:00
parent 7fceb2b3af
commit 7ef96be7dc

View file

@ -12,10 +12,10 @@ define [
else else
return null return null
referenceKeyToAutocompleteEntry = (key) -> referenceKeyToAutocompleteEntry = (commandName, key) ->
return { return {
caption: "\\cite{#{key}", caption: "\\#{commandName}{#{key}",
snippet: "\\cite{#{key}", snippet: "\\#{commandName}{#{key}",
meta: "reference", meta: "reference",
score: 10000 score: 10000
} }
@ -56,20 +56,23 @@ define [
range = new Range(pos.row, 0, pos.row, pos.column) range = new Range(pos.row, 0, pos.row, pos.column)
lineUpToCursor = editor.getSession().getTextRange(range) lineUpToCursor = editor.getSession().getTextRange(range)
commandFragment = getLastCommandFragment(lineUpToCursor) commandFragment = getLastCommandFragment(lineUpToCursor)
if commandFragment and commandFragment.match(/^~?\\cite{\w*/) if commandFragment
result = [] citeMatch = commandFragment.match(/^~?\\(cite[a-z]?){\w*/)
result.push { if citeMatch
caption: "\\cite{", commandName = citeMatch[1]
snippet: "\\cite{", result = []
meta: "reference", result.push {
score: 11000 caption: "\\#{commandName}{",
} snippet: "\\#{commandName}{",
if references.keys and references.keys.length > 0 meta: "reference",
references.keys.forEach (key) -> score: 11000
result.push(referenceKeyToAutocompleteEntry(key)) }
callback null, result if references.keys and references.keys.length > 0
else references.keys.forEach (key) ->
callback null, result result.push(referenceKeyToAutocompleteEntry(commandName, key))
callback null, result
else
callback null, result
@editor.completers = [@suggestionManager, SnippetCompleter, ReferencesCompleter] @editor.completers = [@suggestionManager, SnippetCompleter, ReferencesCompleter]