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

Parse existing `begin` commands too.

Shane Kilkelly 10 лет назад
Родитель
Сommit
d655e99439

+ 15 - 2
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee

@@ -109,14 +109,28 @@ define () ->
 				return names
 				return names
 		return names
 		return names
 
 
+	BEGIN_COMMAND_REGEX = /^\\begin{(\w+)}.*$/gm
+
+	parseBeginCommandNames = (text) ->
+		names = []
+		iterations = 0
+		while match = BEGIN_COMMAND_REGEX.exec(text)
+			names.push match[1]
+			iterations += 1
+			if iterations >= 1000
+				return names
+		return names
+
 	class SnippetManager
 	class SnippetManager
 		getCompletions: (editor, session, pos, prefix, callback) ->
 		getCompletions: (editor, session, pos, prefix, callback) ->
 			# console.log ">> get snippet completions", editor, session, pos, prefix
 			# console.log ">> get snippet completions", editor, session, pos, prefix
 			docText = session.getValue()
 			docText = session.getValue()
 			customEnvironmentNames = parseCustomEnvironmentNames(docText)
 			customEnvironmentNames = parseCustomEnvironmentNames(docText)
+			beginCommandNames = parseBeginCommandNames(docText)
 			# console.log customEnvironmentNames
 			# console.log customEnvironmentNames
+			parsedNames = _.union(customEnvironmentNames, beginCommandNames)
 			snippets = staticSnippets.concat(
 			snippets = staticSnippets.concat(
-				customEnvironmentNames.map (name) ->
+				parsedNames.map (name) ->
 					{
 					{
 						caption: "\\begin{#{name}}..."
 						caption: "\\begin{#{name}}..."
 						snippet: """
 						snippet: """
@@ -125,7 +139,6 @@ define () ->
 							\\end{#{name}}
 							\\end{#{name}}
 						"""
 						"""
 						meta: "env"
 						meta: "env"
-
 					}
 					}
 			)
 			)
 			callback null, snippets
 			callback null, snippets