From 57e9cf282915fb247af8b9cdffa6247f1395e559 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 4 Nov 2020 09:55:14 +0000 Subject: [PATCH] Merge pull request #3304 from overleaf/ns-env-autocomplete-nesting Parse nested environments for autocomplete suggestion GitOrigin-RevId: 1ddfc0e0129801f203084a74c586031ffe0d5bb9 --- .../aceEditor/auto-complete/EnvironmentManager.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js b/services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js index 99e47f5dbd..03b3efa797 100644 --- a/services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js +++ b/services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js @@ -146,20 +146,22 @@ const parseCustomEnvironments = function(text) { const parseBeginCommands = function(text) { let match - const re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm + const re = /^([\t ]*)\\begin{(\w+)}.*\n([\t ]*)/gm const result = [] let iterations = 0 while ((match = re.exec(text))) { + const whitespaceAlignment = match[3].replace(match[1] || '', '') if ( - !Array.from(Environments.all).includes(match[1]) && - match[1] !== 'document' + !Array.from(Environments.all).includes(match[2]) && + match[2] !== 'document' ) { - result.push({ name: match[1], whitespace: match[2] }) + result.push({ name: match[2], whitespace: whitespaceAlignment }) iterations += 1 if (iterations >= 1000) { return result } } + re.lastIndex = match.index + 1 } return result }