|
|
@@ -44,13 +44,11 @@ define [
|
|
|
|
|
|
GraphicsCompleter =
|
|
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
|
|
- context = Helpers.getContext(editor, pos)
|
|
|
- {commandFragment, closingBrace} = context
|
|
|
+ {commandFragment} = Helpers.getContext(editor, pos)
|
|
|
if commandFragment
|
|
|
match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/)
|
|
|
if match
|
|
|
- commandName = match[1]
|
|
|
- currentArg = match[3]
|
|
|
+ [_, commandName, _, currentArg] = match
|
|
|
graphicsPaths = Preamble.getGraphicsPaths()
|
|
|
result = []
|
|
|
for graphic in Graphics.getGraphicsFiles()
|
|
|
@@ -60,8 +58,8 @@ define [
|
|
|
path = path.slice(graphicsPath.length)
|
|
|
break
|
|
|
result.push {
|
|
|
- caption: "\\#{commandName}{#{path}#{closingBrace}"
|
|
|
- value: "\\#{commandName}{#{path}#{closingBrace}"
|
|
|
+ caption: "\\#{commandName}{#{path}}"
|
|
|
+ value: "\\#{commandName}{#{path}}"
|
|
|
meta: "graphic"
|
|
|
score: 50
|
|
|
}
|
|
|
@@ -70,20 +68,18 @@ define [
|
|
|
metadataManager = @metadataManager
|
|
|
FilesCompleter =
|
|
|
getCompletions: (editor, session, pos, prefix, callback) =>
|
|
|
- context = Helpers.getContext(editor, pos)
|
|
|
- {commandFragment, closingBrace} = context
|
|
|
+ {commandFragment} = Helpers.getContext(editor, pos)
|
|
|
if commandFragment
|
|
|
match = commandFragment.match(/^\\(input|include){(\w*)/)
|
|
|
if match
|
|
|
- commandName = match[1]
|
|
|
- currentArg = match[2]
|
|
|
+ [_, commandName, currentArg] = match
|
|
|
result = []
|
|
|
for file in Files.getTeXFiles()
|
|
|
if file.id != @$scope.docId
|
|
|
path = file.path
|
|
|
result.push {
|
|
|
- caption: "\\#{commandName}{#{path}#{closingBrace}"
|
|
|
- value: "\\#{commandName}{#{path}#{closingBrace}"
|
|
|
+ caption: "\\#{commandName}{#{path}}"
|
|
|
+ value: "\\#{commandName}{#{path}}"
|
|
|
meta: "file"
|
|
|
score: 50
|
|
|
}
|
|
|
@@ -91,13 +87,11 @@ define [
|
|
|
|
|
|
LabelsCompleter =
|
|
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
|
|
- context = Helpers.getContext(editor, pos)
|
|
|
- {commandFragment, closingBrace} = context
|
|
|
+ {commandFragment} = Helpers.getContext(editor, pos)
|
|
|
if commandFragment
|
|
|
refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
|
|
|
if refMatch
|
|
|
- commandName = refMatch[1]
|
|
|
- currentArg = refMatch[2]
|
|
|
+ [_, commandName, currentArg] = refMatch
|
|
|
result = []
|
|
|
if commandName != 'ref' # ref is in top 100 commands
|
|
|
result.push {
|
|
|
@@ -108,8 +102,8 @@ define [
|
|
|
}
|
|
|
for label in metadataManager.getAllLabels()
|
|
|
result.push {
|
|
|
- caption: "\\#{commandName}{#{label}#{closingBrace}"
|
|
|
- value: "\\#{commandName}{#{label}#{closingBrace}"
|
|
|
+ caption: "\\#{commandName}{#{label}}"
|
|
|
+ value: "\\#{commandName}{#{label}}"
|
|
|
meta: "cross-reference"
|
|
|
score: 50
|
|
|
}
|
|
|
@@ -118,17 +112,14 @@ define [
|
|
|
references = @$scope.$root._references
|
|
|
ReferencesCompleter =
|
|
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
|
|
- context = Helpers.getContext(editor, pos)
|
|
|
- {commandFragment, closingBrace} = context
|
|
|
+ {commandFragment} = Helpers.getContext(editor, pos)
|
|
|
if commandFragment
|
|
|
citeMatch = commandFragment.match(
|
|
|
/^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/
|
|
|
)
|
|
|
if citeMatch
|
|
|
- commandName = citeMatch[1]
|
|
|
- previousArgs = citeMatch[2]
|
|
|
- currentArg = citeMatch[3]
|
|
|
- if previousArgs == undefined
|
|
|
+ [_, commandName, previousArgs, currentArg] = citeMatch
|
|
|
+ if !previousArgs?
|
|
|
previousArgs = ""
|
|
|
previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs
|
|
|
result = []
|
|
|
@@ -140,10 +131,10 @@ define [
|
|
|
}
|
|
|
if references.keys and references.keys.length > 0
|
|
|
references.keys.forEach (key) ->
|
|
|
- if !(key in [null, undefined])
|
|
|
+ if key?
|
|
|
result.push({
|
|
|
- caption: "\\#{commandName}{#{previousArgsCaption}#{key}#{closingBrace}"
|
|
|
- value: "\\#{commandName}{#{previousArgs}#{key}#{closingBrace}"
|
|
|
+ caption: "\\#{commandName}{#{previousArgsCaption}#{key}}"
|
|
|
+ value: "\\#{commandName}{#{previousArgs}#{key}}"
|
|
|
meta: "reference"
|
|
|
score: 50
|
|
|
})
|
|
|
@@ -170,8 +161,7 @@ define [
|
|
|
onChange: (change) ->
|
|
|
cursorPosition = @editor.getCursorPosition()
|
|
|
end = change.end
|
|
|
- context = Helpers.getContext(@editor, end)
|
|
|
- {lineUpToCursor, commandFragment} = context
|
|
|
+ {lineUpToCursor, commandFragment} = Helpers.getContext(@editor, end)
|
|
|
if lineUpToCursor.match(/.*%.*/)
|
|
|
return
|
|
|
lastCharIsBackslash = lineUpToCursor.slice(-1) == "\\"
|
|
|
@@ -188,10 +178,19 @@ define [
|
|
|
end.row == cursorPosition.row and
|
|
|
end.column == cursorPosition.column + 1
|
|
|
)
|
|
|
- if (commandFragment? and commandFragment.length > 2) or lastCharIsBackslash
|
|
|
+ if commandFragment?.length > 2 or lastCharIsBackslash
|
|
|
setTimeout () =>
|
|
|
@editor.execCommand("startAutocomplete")
|
|
|
, 0
|
|
|
+ if (
|
|
|
+ change.action == "insert" and
|
|
|
+ change.lines[0].match(/\\(\w+){}/)?[1].match(
|
|
|
+ /(begin|end|[a-z]*ref|usepackage|[a-z]*cite[a-z]*|input|include)/
|
|
|
+ )
|
|
|
+ )
|
|
|
+ setTimeout () =>
|
|
|
+ @editor.execCommand("startAutocomplete")
|
|
|
+ , 0
|
|
|
|
|
|
monkeyPatchAutocomplete: () ->
|
|
|
Autocomplete = ace.require("ace/autocomplete").Autocomplete
|
|
|
@@ -209,7 +208,7 @@ define [
|
|
|
|
|
|
# If we are in \begin{it|}, then we need to remove the trailing }
|
|
|
# since it will be adding in with the autocomplete of \begin{item}...
|
|
|
- if this.completions.filterText.match(/^\\begin\{/) and nextChar == "}"
|
|
|
+ if this.completions.filterText.match(/^\\\w+{/) and nextChar == "}"
|
|
|
editor.session.remove(range)
|
|
|
|
|
|
# Provide our own `insertMatch` implementation.
|