From 863128a03035130fb797d1a99ed78f5da9552bb2 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Tue, 5 Jun 2018 10:08:27 -0400 Subject: [PATCH 1/2] only suggest one document environment in project --- .../auto-complete/AutoCompleteManager.coffee | 5 ++-- .../auto-complete/EnvironmentManager.coffee | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index 78d12eebc3..a10dcf618b 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -34,8 +34,7 @@ define [ enableLiveAutocompletion: false }) - commandCompleter = new CommandManager(@metadataManager) - + CommandCompleter = new CommandManager(@metadataManager) SnippetCompleter = new EnvironmentManager() PackageCompleter = new PackageManager(@metadataManager, Helpers) @@ -153,7 +152,7 @@ define [ callback null, result @editor.completers = [ - commandCompleter + CommandCompleter SnippetCompleter PackageCompleter ReferencesCompleter diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee index 8208ec4a30..ca79f27bf4 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee @@ -23,7 +23,7 @@ define () -> "thebibliography" ] - environmentNames = snippetNames.concat environments + environmentNames = snippetNames.concat(environments) staticSnippets = for env in environments { @@ -122,6 +122,18 @@ define () -> meta: "env" }] + documentSnippet = { + caption: "\\begin{document}..." + snippet: """ + \\begin{document} + $1 + \\end{document} + """ + meta: "env" + } + + staticSnippets.push(documentSnippet) + parseCustomEnvironments = (text) -> re = /^\\newenvironment{(\w+)}.*$/gm result = [] @@ -138,18 +150,31 @@ define () -> result = [] iterations = 0 while match = re.exec(text) - if match[1] not in environmentNames + if match[1] not in environmentNames and match[1] != "document" result.push {name: match[1], whitespace: match[2]} iterations += 1 if iterations >= 1000 return result return result + hasDocumentEnvironment = (text) -> + re = /^\\begin{document}/m + envs = [] + iterations = 0 + return re.exec(text) != null + class EnvironmentManager getCompletions: (editor, session, pos, prefix, callback) -> docText = session.getValue() customEnvironments = parseCustomEnvironments(docText) beginCommands = parseBeginCommands(docText) + if hasDocumentEnvironment(docText) + ind = staticSnippets.indexOf(documentSnippet) + if ind != -1 + staticSnippets.splice(ind, 1) + else + staticSnippets.push documentSnippet + parsedItemsMap = {} for environment in customEnvironments parsedItemsMap[environment.name] = environment From 26385718e6df65fbd8aa07d14b34a62227651d22 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Tue, 5 Jun 2018 11:02:03 -0400 Subject: [PATCH 2/2] only suggest thebibliography once --- .../auto-complete/EnvironmentManager.coffee | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee index ca79f27bf4..383bf1bd2e 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee @@ -111,15 +111,6 @@ define () -> \\end{frame} """ meta: "env" - }, { - caption: "\\begin{thebibliography}..." - snippet: """ - \\begin{thebibliography}{$1} - \\bibitem{$2} - $3 - \\end{thebibliography} - """ - meta: "env" }] documentSnippet = { @@ -132,6 +123,16 @@ define () -> meta: "env" } + bibliographySnippet = { + caption: "\\begin{thebibliography}..." + snippet: """ + \\begin{thebibliography}{$1} + \\bibitem{$2} + $3 + \\end{thebibliography} + """ + meta: "env" + } staticSnippets.push(documentSnippet) parseCustomEnvironments = (text) -> @@ -163,6 +164,12 @@ define () -> iterations = 0 return re.exec(text) != null + hasBibliographyEnvironment = (text) -> + re = /^\\begin{thebibliography}/m + envs = [] + iterations = 0 + return re.exec(text) != null + class EnvironmentManager getCompletions: (editor, session, pos, prefix, callback) -> docText = session.getValue() @@ -175,6 +182,13 @@ define () -> else staticSnippets.push documentSnippet + if hasBibliographyEnvironment(docText) + ind = staticSnippets.indexOf(bibliographySnippet) + if ind != -1 + staticSnippets.splice(ind, 1) + else + staticSnippets.push bibliographySnippet + parsedItemsMap = {} for environment in customEnvironments parsedItemsMap[environment.name] = environment