From d655e99439b227ecfede1a480651c2a6094d0364 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 12:07:21 +0000 Subject: [PATCH] Parse existing `begin` commands too. --- .../auto-complete/SnippetManager.coffee | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index cc894ad39d..438e83fd6b 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -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