From c25c2b676a4144733b8098d3d22cc2c1a7548a98 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 11:14:05 +0000 Subject: [PATCH] Parse `\newenvironment{}` commands. --- .../auto-complete/SnippetManager.coffee | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 5cf040f9d6..d09c8d9013 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 @@ -97,9 +97,24 @@ define () -> meta: "env" }] + CUSTOM_ENVIRONMENT_REGEX = /^\\newenvironment{(\w+)}.*$/gm + + parseCustomEnvironmentNames = (text) -> + names = [] + iterations = 0 + while match = CUSTOM_ENVIRONMENT_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" + # console.log ">> get snippet completions", editor, session, pos, prefix + docText = session.getValue() + customEnvironmentNames = parseCustomEnvironmentNames(docText) + # console.log customEnvironmentNames callback null, staticSnippets return SnippetManager