Просмотр исходного кода

Merge pull request #3304 from overleaf/ns-env-autocomplete-nesting

Parse nested environments for autocomplete suggestion

GitOrigin-RevId: 1ddfc0e0129801f203084a74c586031ffe0d5bb9
Shane Kilkelly 6 лет назад
Родитель
Сommit
57e9cf2829

+ 6 - 4
services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js

@@ -146,20 +146,22 @@ const parseCustomEnvironments = function(text) {
 
 
 const parseBeginCommands = function(text) {
 const parseBeginCommands = function(text) {
   let match
   let match
-  const re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm
+  const re = /^([\t ]*)\\begin{(\w+)}.*\n([\t ]*)/gm
   const result = []
   const result = []
   let iterations = 0
   let iterations = 0
   while ((match = re.exec(text))) {
   while ((match = re.exec(text))) {
+    const whitespaceAlignment = match[3].replace(match[1] || '', '')
     if (
     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
       iterations += 1
       if (iterations >= 1000) {
       if (iterations >= 1000) {
         return result
         return result
       }
       }
     }
     }
+    re.lastIndex = match.index + 1
   }
   }
   return result
   return result
 }
 }