mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Parse existing begin
commands too.
This commit is contained in:
parent
eebd25351d
commit
d655e99439
1 changed files with 15 additions and 2 deletions
|
@ -109,14 +109,28 @@ define () ->
|
|||
return names
|
||||
return names
|
||||
|
||||
BEGIN_COMMAND_REGEX = /^\\begin{(\w+)}.*$/gm
|
||||
|
||||
parseBeginCommandNames = (text) ->
|
||||
names = []
|
||||
iterations = 0
|
||||
while match = BEGIN_COMMAND_REGEX.exec(text)
|
||||
names.push match[1]
|
||||
iterations += 1
|
||||
if iterations >= 1000
|
||||
return names
|
||||
return names
|
||||
|
||||
class SnippetManager
|
||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||
# console.log ">> get snippet completions", editor, session, pos, prefix
|
||||
docText = session.getValue()
|
||||
customEnvironmentNames = parseCustomEnvironmentNames(docText)
|
||||
beginCommandNames = parseBeginCommandNames(docText)
|
||||
# console.log customEnvironmentNames
|
||||
parsedNames = _.union(customEnvironmentNames, beginCommandNames)
|
||||
snippets = staticSnippets.concat(
|
||||
customEnvironmentNames.map (name) ->
|
||||
parsedNames.map (name) ->
|
||||
{
|
||||
caption: "\\begin{#{name}}..."
|
||||
snippet: """
|
||||
|
@ -125,7 +139,6 @@ define () ->
|
|||
\\end{#{name}}
|
||||
"""
|
||||
meta: "env"
|
||||
|
||||
}
|
||||
)
|
||||
callback null, snippets
|
||||
|
|
Loading…
Reference in a new issue