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..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 @@ -23,7 +23,7 @@ define () -> "thebibliography" ] - environmentNames = snippetNames.concat environments + environmentNames = snippetNames.concat(environments) staticSnippets = for env in environments { @@ -111,7 +111,19 @@ define () -> \\end{frame} """ meta: "env" - }, { + }] + + documentSnippet = { + caption: "\\begin{document}..." + snippet: """ + \\begin{document} + $1 + \\end{document} + """ + meta: "env" + } + + bibliographySnippet = { caption: "\\begin{thebibliography}..." snippet: """ \\begin{thebibliography}{$1} @@ -120,7 +132,8 @@ define () -> \\end{thebibliography} """ meta: "env" - }] + } + staticSnippets.push(documentSnippet) parseCustomEnvironments = (text) -> re = /^\\newenvironment{(\w+)}.*$/gm @@ -138,18 +151,44 @@ 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 + + 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() customEnvironments = parseCustomEnvironments(docText) beginCommands = parseBeginCommands(docText) + if hasDocumentEnvironment(docText) + ind = staticSnippets.indexOf(documentSnippet) + if ind != -1 + staticSnippets.splice(ind, 1) + 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