mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 16:22:06 -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
|
||||||
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
|
class SnippetManager
|
||||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||||
# console.log ">> get snippet completions", editor, session, pos, prefix
|
# console.log ">> get snippet completions", editor, session, pos, prefix
|
||||||
docText = session.getValue()
|
docText = session.getValue()
|
||||||
customEnvironmentNames = parseCustomEnvironmentNames(docText)
|
customEnvironmentNames = parseCustomEnvironmentNames(docText)
|
||||||
|
beginCommandNames = parseBeginCommandNames(docText)
|
||||||
# console.log customEnvironmentNames
|
# console.log customEnvironmentNames
|
||||||
|
parsedNames = _.union(customEnvironmentNames, beginCommandNames)
|
||||||
snippets = staticSnippets.concat(
|
snippets = staticSnippets.concat(
|
||||||
customEnvironmentNames.map (name) ->
|
parsedNames.map (name) ->
|
||||||
{
|
{
|
||||||
caption: "\\begin{#{name}}..."
|
caption: "\\begin{#{name}}..."
|
||||||
snippet: """
|
snippet: """
|
||||||
|
@ -125,7 +139,6 @@ define () ->
|
||||||
\\end{#{name}}
|
\\end{#{name}}
|
||||||
"""
|
"""
|
||||||
meta: "env"
|
meta: "env"
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
callback null, snippets
|
callback null, snippets
|
||||||
|
|
Loading…
Reference in a new issue