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

fixing command duplication issue during suggestion

Nate Stemen 9 лет назад
Родитель
Сommit
f253b7e8cb

+ 0 - 75
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee

@@ -1,75 +1,4 @@
 define () ->
 define () ->
-	noArgumentCommands = [
-		'item', 'hline', 'lipsum', 'centering', 'noindent', 'textwidth', 'draw',
-		'maketitle', 'newpage', 'verb', 'bibliography', 'fi', 'hfill', 'par',
-		'in', 'sum', 'cdot', 'alpha', 'ldots', 'else', 'linewidth', 'left',
-		'right', 'today', 'clearpage', 'newline', 'endinput', 'mu',
-		'tableofcontents', 'vfill', 'bigskip', 'fill', 'cleardoublepage'
-	]
-	singleArgumentCommands = [
-		'chapter', 'usepackage', 'section', 'label', 'textbf', 'subsection',
-		'vspace', 'cite', 'textit', 'documentclass', 'includegraphics', 'input',
-		'emph','caption', 'ref', 'title', 'author', 'texttt', 'include',
-		'hspace', 'bibitem', 'url', 'large', 'subsubsection', 'textsc', 'date',
-		'footnote', 'small', 'thanks', 'underline', 'graphicspath', 'pageref',
-		'section*', 'subsection*', 'subsubsection*', 'sqrt', 'text',
-		'normalsize', 'Large', 'paragraph', 'pagestyle', 'thispagestyle',
-		'bibliographystyle'
-	]
-	doubleArgumentCommands = [
-		'newcommand', 'frac', 'renewcommand', 'setlength', 'href', 'newtheorem'
-	]
-	tripleArgumentCommands = [
-		'addcontentsline', 'newacronym', 'multicolumn'
-	]
-	special = ['LaTeX', 'TeX']
-
-	noArgumentCommands = for com in noArgumentCommands
-		{
-			caption: "\\#{com}"
-			snippet: "\\#{com}"
-			meta: "cmd"
-		}
-	singleArgumentCommands = for com in singleArgumentCommands
-		{
-			caption: "\\#{com}{}"
-			snippet: "\\#{com}{$1}"
-			meta: "cmd"
-		}
-	doubleArgumentCommands = for com in doubleArgumentCommands
-		{
-			caption: "\\#{com}{}{}"
-			snippet: "\\#{com}{$1}{$2}"
-			meta: "cmd"
-		}
-	tripleArgumentCommands = for com in tripleArgumentCommands
-		{
-			caption: "\\#{com}{}{}{}"
-			snippet: "\\#{com}{$1}{$2}{$3}"
-			meta: "cmd"
-		}
-	special = for cmd in special
-		if cmd == 'TeX'
-			{
-				caption: "\\TeX{}"
-				snippet: "\\TeX{}"
-				meta: "cmd"
-			}
-		else if com == 'LaTeX'
-			{
-				caption: "\\LaTeX{}"
-				snippet: "\\LaTeX{}"
-				meta: "cmd"
-			}
-
-	staticCommands = [].concat(
-						noArgumentCommands,
-						singleArgumentCommands,
-						doubleArgumentCommands,
-						tripleArgumentCommands,
-						special
-					)
-
 	environments = [
 	environments = [
 		"abstract",
 		"abstract",
 		"align", "align*",
 		"align", "align*",
@@ -178,9 +107,6 @@ define () ->
 		"""
 		"""
 	}]
 	}]
 
 
-	staticSnippets = staticSnippets.concat staticCommands
-
-
 	parseCustomEnvironments = (text) ->
 	parseCustomEnvironments = (text) ->
 		re = /^\\newenvironment{(\w+)}.*$/gm
 		re = /^\\newenvironment{(\w+)}.*$/gm
 		result = []
 		result = []
@@ -192,7 +118,6 @@ define () ->
 				return result
 				return result
 		return result
 		return result
 
 
-
 	parseBeginCommands = (text) ->
 	parseBeginCommands = (text) ->
 		re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm
 		re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm
 		result = []
 		result = []

+ 93 - 20
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee

@@ -1,4 +1,75 @@
 define [], () ->
 define [], () ->
+	noArgumentCommands = [
+		'item', 'hline', 'lipsum', 'centering', 'noindent', 'textwidth', 'draw',
+		'maketitle', 'newpage', 'verb', 'bibliography', 'fi', 'hfill', 'par',
+		'in', 'sum', 'cdot', 'alpha', 'ldots', 'else', 'linewidth', 'left',
+		'right', 'today', 'clearpage', 'newline', 'endinput', 'mu',
+		'tableofcontents', 'vfill', 'bigskip', 'fill', 'cleardoublepage'
+	]
+	singleArgumentCommands = [
+		'chapter', 'usepackage', 'section', 'label', 'textbf', 'subsection',
+		'vspace', 'cite', 'textit', 'documentclass', 'includegraphics', 'input',
+		'emph','caption', 'ref', 'title', 'author', 'texttt', 'include',
+		'hspace', 'bibitem', 'url', 'large', 'subsubsection', 'textsc', 'date',
+		'footnote', 'small', 'thanks', 'underline', 'graphicspath', 'pageref',
+		'section*', 'subsection*', 'subsubsection*', 'sqrt', 'text',
+		'normalsize', 'Large', 'paragraph', 'pagestyle', 'thispagestyle',
+		'bibliographystyle'
+	]
+	doubleArgumentCommands = [
+		'newcommand', 'frac', 'renewcommand', 'setlength', 'href', 'newtheorem'
+	]
+	tripleArgumentCommands = [
+		'addcontentsline', 'newacronym', 'multicolumn'
+	]
+	special = ['LaTeX', 'TeX']
+
+	rawCommands = [].concat(
+						noArgumentCommands,
+						singleArgumentCommands,
+						doubleArgumentCommands,
+						tripleArgumentCommands,
+						special
+					)
+
+	noArgumentCommands = for cmd in noArgumentCommands
+		{
+			caption: "\\#{cmd}"
+			snippet: "\\#{cmd}"
+			meta: "cmd"
+		}
+	singleArgumentCommands = for cmd in singleArgumentCommands
+		{
+			caption: "\\#{cmd}{}"
+			snippet: "\\#{cmd}{$1}"
+			meta: "cmd"
+		}
+	doubleArgumentCommands = for cmd in doubleArgumentCommands
+		{
+			caption: "\\#{cmd}{}{}"
+			snippet: "\\#{cmd}{$1}{$2}"
+			meta: "cmd"
+		}
+	tripleArgumentCommands = for cmd in tripleArgumentCommands
+		{
+			caption: "\\#{cmd}{}{}{}"
+			snippet: "\\#{cmd}{$1}{$2}{$3}"
+			meta: "cmd"
+		}
+	special = for cmd in special
+			{
+				caption: "\\#{cmd}{}"
+				snippet: "\\#{cmd}{}"
+				meta: "cmd"
+			}
+
+	staticCommands = [].concat(
+						noArgumentCommands,
+						singleArgumentCommands,
+						doubleArgumentCommands,
+						tripleArgumentCommands,
+						special
+					)
 
 
 	class Parser
 	class Parser
 		constructor: (@doc, @prefix) ->
 		constructor: (@doc, @prefix) ->
@@ -95,26 +166,28 @@ define [], () ->
 			commands = parser.parse()
 			commands = parser.parse()
 			completions = []
 			completions = []
 			for command in commands
 			for command in commands
-				caption = "\\#{command[0]}"
-				score = if caption == prefix then 99 else 50
-				snippet = caption
-				i = 1
-				_.times command[1], () ->
-					snippet += "[${#{i}}]"
-					caption += "[]"
-					i++
-				_.times command[2], () ->
-					snippet += "{${#{i}}}"
-					caption += "{}"
-					i++
-				completions.push {
-					caption: caption
-					snippet: snippet
-					meta: "cmd"
-					score: score
-				}
-
-			callback null, completions
+				if command[0] not in rawCommands
+					caption = "\\#{command[0]}"
+					score = if caption == prefix then 99 else 50
+					snippet = caption
+					i = 1
+					_.times command[1], () ->
+						snippet += "[${#{i}}]"
+						caption += "[]"
+						i++
+					_.times command[2], () ->
+						snippet += "{${#{i}}}"
+						caption += "{}"
+						i++
+					completions.push {
+						caption: caption
+						snippet: snippet
+						meta: "cmd"
+						score: score
+					}
+			completions = completions.concat staticCommands
+
+			callback(null, completions)
 
 
 		loadCommandsFromDoc: (doc) ->
 		loadCommandsFromDoc: (doc) ->
 			parser = new Parser(doc)
 			parser = new Parser(doc)