mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 11:33:07 +00:00
move end bracket logic to helpers and remove unecessary unpacking
This commit is contained in:
parent
30eca714eb
commit
91302cfb16
2 changed files with 30 additions and 28 deletions
|
@ -29,15 +29,15 @@ define [
|
||||||
|
|
||||||
enable: () ->
|
enable: () ->
|
||||||
@editor.setOptions({
|
@editor.setOptions({
|
||||||
enableBasicAutocompletion: true,
|
enableBasicAutocompletion: true
|
||||||
enableSnippets: true,
|
enableSnippets: true
|
||||||
enableLiveAutocompletion: false
|
enableLiveAutocompletion: false
|
||||||
})
|
})
|
||||||
|
|
||||||
commandCompleter = new CommandManager(@metadataManager)
|
commandCompleter = new CommandManager(@metadataManager)
|
||||||
|
|
||||||
SnippetCompleter = new EnvironmentManager()
|
SnippetCompleter = new EnvironmentManager()
|
||||||
PackageCompleter = new PackageManager(@metadataManager)
|
PackageCompleter = new PackageManager(@metadataManager, Helpers)
|
||||||
|
|
||||||
Graphics = @graphics
|
Graphics = @graphics
|
||||||
Preamble = @preamble
|
Preamble = @preamble
|
||||||
|
@ -46,7 +46,7 @@ define [
|
||||||
GraphicsCompleter =
|
GraphicsCompleter =
|
||||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||||
context = Helpers.getContext(editor, pos)
|
context = Helpers.getContext(editor, pos)
|
||||||
{lineUpToCursor, commandFragment, lineBeyondCursor, needsClosingBrace} = context
|
{commandFragment, closingBrace} = context
|
||||||
if commandFragment
|
if commandFragment
|
||||||
match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/)
|
match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/)
|
||||||
if match
|
if match
|
||||||
|
@ -61,9 +61,9 @@ define [
|
||||||
path = path.slice(graphicsPath.length)
|
path = path.slice(graphicsPath.length)
|
||||||
break
|
break
|
||||||
result.push {
|
result.push {
|
||||||
caption: "\\#{commandName}{#{path}#{if needsClosingBrace then '}' else ''}",
|
caption: "\\#{commandName}{#{path}#{closingBrace}"
|
||||||
value: "\\#{commandName}{#{path}#{if needsClosingBrace then '}' else ''}",
|
value: "\\#{commandName}{#{path}#{closingBrace}"
|
||||||
meta: "graphic",
|
meta: "graphic"
|
||||||
score: 50
|
score: 50
|
||||||
}
|
}
|
||||||
callback null, result
|
callback null, result
|
||||||
|
@ -72,7 +72,7 @@ define [
|
||||||
FilesCompleter =
|
FilesCompleter =
|
||||||
getCompletions: (editor, session, pos, prefix, callback) =>
|
getCompletions: (editor, session, pos, prefix, callback) =>
|
||||||
context = Helpers.getContext(editor, pos)
|
context = Helpers.getContext(editor, pos)
|
||||||
{lineUpToCursor, commandFragment, lineBeyondCursor, needsClosingBrace} = context
|
{commandFragment, closingBrace} = context
|
||||||
if commandFragment
|
if commandFragment
|
||||||
match = commandFragment.match(/^\\(input|include){(\w*)/)
|
match = commandFragment.match(/^\\(input|include){(\w*)/)
|
||||||
if match
|
if match
|
||||||
|
@ -83,9 +83,9 @@ define [
|
||||||
if file.id != @$scope.docId
|
if file.id != @$scope.docId
|
||||||
path = file.path
|
path = file.path
|
||||||
result.push {
|
result.push {
|
||||||
caption: "\\#{commandName}{#{path}#{if needsClosingBrace then '}' else ''}",
|
caption: "\\#{commandName}{#{path}#{closingBrace}"
|
||||||
value: "\\#{commandName}{#{path}#{if needsClosingBrace then '}' else ''}",
|
value: "\\#{commandName}{#{path}#{closingBrace}"
|
||||||
meta: "file",
|
meta: "file"
|
||||||
score: 50
|
score: 50
|
||||||
}
|
}
|
||||||
callback null, result
|
callback null, result
|
||||||
|
@ -93,7 +93,7 @@ define [
|
||||||
LabelsCompleter =
|
LabelsCompleter =
|
||||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||||
context = Helpers.getContext(editor, pos)
|
context = Helpers.getContext(editor, pos)
|
||||||
{lineUpToCursor, commandFragment, lineBeyondCursor, needsClosingBrace} = context
|
{commandFragment, closingBrace} = context
|
||||||
if commandFragment
|
if commandFragment
|
||||||
refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
|
refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
|
||||||
if refMatch
|
if refMatch
|
||||||
|
@ -102,16 +102,16 @@ define [
|
||||||
result = []
|
result = []
|
||||||
if commandName != 'ref' # ref is in top 100 commands
|
if commandName != 'ref' # ref is in top 100 commands
|
||||||
result.push {
|
result.push {
|
||||||
caption: "\\#{commandName}{}",
|
caption: "\\#{commandName}{}"
|
||||||
snippet: "\\#{commandName}{}",
|
snippet: "\\#{commandName}{}"
|
||||||
meta: "cross-reference",
|
meta: "cross-reference"
|
||||||
score: 60
|
score: 60
|
||||||
}
|
}
|
||||||
for label in metadataManager.getAllLabels()
|
for label in metadataManager.getAllLabels()
|
||||||
result.push {
|
result.push {
|
||||||
caption: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
|
caption: "\\#{commandName}{#{label}#{closingBrace}"
|
||||||
value: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
|
value: "\\#{commandName}{#{label}#{closingBrace}"
|
||||||
meta: "cross-reference",
|
meta: "cross-reference"
|
||||||
score: 50
|
score: 50
|
||||||
}
|
}
|
||||||
callback null, result
|
callback null, result
|
||||||
|
@ -120,7 +120,7 @@ define [
|
||||||
ReferencesCompleter =
|
ReferencesCompleter =
|
||||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||||
context = Helpers.getContext(editor, pos)
|
context = Helpers.getContext(editor, pos)
|
||||||
{lineUpToCursor, commandFragment, lineBeyondCursor, needsClosingBrace} = context
|
{commandFragment, closingBrace} = context
|
||||||
if commandFragment
|
if commandFragment
|
||||||
citeMatch = commandFragment.match(
|
citeMatch = commandFragment.match(
|
||||||
/^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/
|
/^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/
|
||||||
|
@ -134,18 +134,18 @@ 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: 60
|
score: 60
|
||||||
}
|
}
|
||||||
if references.keys and references.keys.length > 0
|
if references.keys and references.keys.length > 0
|
||||||
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}#{if needsClosingBrace then '}' else ''}",
|
caption: "\\#{commandName}{#{previousArgsCaption}#{key}#{closingBrace}"
|
||||||
value: "\\#{commandName}{#{previousArgs}#{key}#{if needsClosingBrace then '}' else ''}",
|
value: "\\#{commandName}{#{previousArgs}#{key}#{closingBrace}"
|
||||||
meta: "reference",
|
meta: "reference"
|
||||||
score: 50
|
score: 50
|
||||||
})
|
})
|
||||||
callback null, result
|
callback null, result
|
||||||
|
@ -155,7 +155,7 @@ define [
|
||||||
@editor.completers = [
|
@editor.completers = [
|
||||||
commandCompleter
|
commandCompleter
|
||||||
SnippetCompleter
|
SnippetCompleter
|
||||||
PackageCompleter
|
PackageCompleter
|
||||||
ReferencesCompleter
|
ReferencesCompleter
|
||||||
LabelsCompleter
|
LabelsCompleter
|
||||||
GraphicsCompleter
|
GraphicsCompleter
|
||||||
|
@ -172,7 +172,7 @@ define [
|
||||||
cursorPosition = @editor.getCursorPosition()
|
cursorPosition = @editor.getCursorPosition()
|
||||||
end = change.end
|
end = change.end
|
||||||
context = Helpers.getContext(@editor, end)
|
context = Helpers.getContext(@editor, end)
|
||||||
{lineUpToCursor, commandFragment, commandName, lineBeyondCursor, needsClosingBrace} = context
|
{lineUpToCursor, commandFragment} = context
|
||||||
if lineUpToCursor.match(/.*%.*/)
|
if lineUpToCursor.match(/.*%.*/)
|
||||||
return
|
return
|
||||||
lastCharIsBackslash = lineUpToCursor.slice(-1) == "\\"
|
lastCharIsBackslash = lineUpToCursor.slice(-1) == "\\"
|
||||||
|
|
|
@ -34,12 +34,14 @@ define [
|
||||||
beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999)
|
beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999)
|
||||||
lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
|
lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
|
||||||
needsClosingBrace = !lineBeyondCursor.match(/^[^{]*}/)
|
needsClosingBrace = !lineBeyondCursor.match(/^[^{]*}/)
|
||||||
|
closingBrace = if needsClosingBrace then '}' else ''
|
||||||
return {
|
return {
|
||||||
lineUpToCursor,
|
lineUpToCursor,
|
||||||
commandFragment,
|
commandFragment,
|
||||||
commandName,
|
commandName,
|
||||||
lineBeyondCursor,
|
lineBeyondCursor,
|
||||||
needsClosingBrace
|
needsClosingBrace,
|
||||||
|
closingBrace
|
||||||
}
|
}
|
||||||
|
|
||||||
return Helpers
|
return Helpers
|
||||||
|
|
Loading…
Reference in a new issue