Support variations of \ref{}, such as \cref{}, \eqref{}, etc..

This commit is contained in:
Shane Kilkelly 2017-06-14 15:15:07 +01:00
parent b0ff8e0745
commit 3f1a440d66

View file

@ -47,23 +47,24 @@ define [
lineUpToCursor = editor.getSession().getTextRange(upToCursorRange)
commandFragment = getLastCommandFragment(lineUpToCursor)
if commandFragment
refMatch = commandFragment.match(/^~?\\ref{([^}]*, *)?(\w*)/)
refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
if refMatch
beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999)
lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
needsClosingBrace = !lineBeyondCursor.match(/^[^{]*}/)
currentArg = refMatch[1]
commandName = refMatch[1]
currentArg = refMatch[2]
result = []
result.push {
caption: "\\ref{}",
snippet: "\\ref{}",
caption: "\\#{commandName}{}",
snippet: "\\#{commandName}{}",
meta: "cross-reference",
score: 11000
}
for label in labelsManager.getAllLabels()
result.push {
caption: "\\ref{#{label}#{if needsClosingBrace then '}' else ''}",
value: "\\ref{#{label}#{if needsClosingBrace then '}' else ''}",
caption: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
value: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
meta: "cross-reference",
score: 10000
}