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

remove trailing } for all commands rather than relying on Helpers module

Nate Stemen 8 лет назад
Родитель
Сommit
e7038f0a57

+ 21 - 19
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee

@@ -44,11 +44,11 @@ define [
 
 
 			GraphicsCompleter =
 			GraphicsCompleter =
 				getCompletions: (editor, session, pos, prefix, callback) ->
 				getCompletions: (editor, session, pos, prefix, callback) ->
-					{commandFragment, closingBrace} = Helpers.getContext(editor, pos)
+					{commandFragment} = Helpers.getContext(editor, pos)
 					if commandFragment
 					if commandFragment
 						match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/)
 						match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/)
 						if match
 						if match
-							[commandName, _, currentArg] = match
+							[_, commandName, _, currentArg] = match
 							graphicsPaths = Preamble.getGraphicsPaths()
 							graphicsPaths = Preamble.getGraphicsPaths()
 							result = []
 							result = []
 							for graphic in Graphics.getGraphicsFiles()
 							for graphic in Graphics.getGraphicsFiles()
@@ -58,8 +58,8 @@ define [
 										path = path.slice(graphicsPath.length)
 										path = path.slice(graphicsPath.length)
 										break
 										break
 								result.push {
 								result.push {
-									caption: "\\#{commandName}{#{path}#{closingBrace}"
-									value: "\\#{commandName}{#{path}#{closingBrace}"
+									caption: "\\#{commandName}{#{path}}"
+									value: "\\#{commandName}{#{path}}"
 									meta: "graphic"
 									meta: "graphic"
 									score: 50
 									score: 50
 								}
 								}
@@ -68,18 +68,18 @@ define [
 			metadataManager = @metadataManager
 			metadataManager = @metadataManager
 			FilesCompleter =
 			FilesCompleter =
 				getCompletions: (editor, session, pos, prefix, callback) =>
 				getCompletions: (editor, session, pos, prefix, callback) =>
-					{commandFragment, closingBrace} = Helpers.getContext(editor, pos)
+					{commandFragment} = Helpers.getContext(editor, pos)
 					if commandFragment
 					if commandFragment
 						match = commandFragment.match(/^\\(input|include){(\w*)/)
 						match = commandFragment.match(/^\\(input|include){(\w*)/)
 						if match
 						if match
-							[commandName, currentArg] = match
+							[_, commandName, currentArg] = match
 							result = []
 							result = []
 							for file in Files.getTeXFiles()
 							for file in Files.getTeXFiles()
 								if file.id != @$scope.docId
 								if file.id != @$scope.docId
 									path = file.path
 									path = file.path
 									result.push {
 									result.push {
-										caption: "\\#{commandName}{#{path}#{closingBrace}"
-										value: "\\#{commandName}{#{path}#{closingBrace}"
+										caption: "\\#{commandName}{#{path}}"
+										value: "\\#{commandName}{#{path}}"
 										meta: "file"
 										meta: "file"
 										score: 50
 										score: 50
 									}
 									}
@@ -87,11 +87,11 @@ define [
 
 
 			LabelsCompleter =
 			LabelsCompleter =
 				getCompletions: (editor, session, pos, prefix, callback) ->
 				getCompletions: (editor, session, pos, prefix, callback) ->
-					{commandFragment, closingBrace} = Helpers.getContext(editor, pos)
+					{commandFragment} = Helpers.getContext(editor, pos)
 					if commandFragment
 					if commandFragment
 						refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
 						refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
 						if refMatch
 						if refMatch
-							[commandName, currentArg] = refMatch
+							[_, commandName, currentArg] = refMatch
 							result = []
 							result = []
 							if commandName != 'ref' # ref is in top 100 commands
 							if commandName != 'ref' # ref is in top 100 commands
 								result.push {
 								result.push {
@@ -102,8 +102,8 @@ define [
 								}
 								}
 							for label in metadataManager.getAllLabels()
 							for label in metadataManager.getAllLabels()
 								result.push {
 								result.push {
-									caption: "\\#{commandName}{#{label}#{closingBrace}"
-									value: "\\#{commandName}{#{label}#{closingBrace}"
+									caption: "\\#{commandName}{#{label}}"
+									value: "\\#{commandName}{#{label}}"
 									meta: "cross-reference"
 									meta: "cross-reference"
 									score: 50
 									score: 50
 								}
 								}
@@ -112,13 +112,13 @@ define [
 			references = @$scope.$root._references
 			references = @$scope.$root._references
 			ReferencesCompleter =
 			ReferencesCompleter =
 				getCompletions: (editor, session, pos, prefix, callback) ->
 				getCompletions: (editor, session, pos, prefix, callback) ->
-					{commandFragment, closingBrace} = Helpers.getContext(editor, pos)
+					{commandFragment} = Helpers.getContext(editor, pos)
 					if commandFragment
 					if commandFragment
 						citeMatch = commandFragment.match(
 						citeMatch = commandFragment.match(
 							/^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/
 							/^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/
 						)
 						)
 						if citeMatch
 						if citeMatch
-							[commandName, previousArgs, currentArg] = citeMatch
+							[_, commandName, previousArgs, currentArg] = citeMatch
 							if !previousArgs?
 							if !previousArgs?
 								previousArgs = ""
 								previousArgs = ""
 							previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs
 							previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs
@@ -133,8 +133,8 @@ define [
 								references.keys.forEach (key) ->
 								references.keys.forEach (key) ->
 									if key?
 									if key?
 										result.push({
 										result.push({
-											caption: "\\#{commandName}{#{previousArgsCaption}#{key}#{closingBrace}"
-											value: "\\#{commandName}{#{previousArgs}#{key}#{closingBrace}"
+											caption: "\\#{commandName}{#{previousArgsCaption}#{key}}"
+											value: "\\#{commandName}{#{previousArgs}#{key}}"
 											meta: "reference"
 											meta: "reference"
 											score: 50
 											score: 50
 										})
 										})
@@ -178,13 +178,15 @@ define [
 				end.row == cursorPosition.row and
 				end.row == cursorPosition.row and
 				end.column == cursorPosition.column + 1
 				end.column == cursorPosition.column + 1
 			)
 			)
-				if (commandFragment? and commandFragment.length > 2) or lastCharIsBackslash
+				if commandFragment?.length > 2 or lastCharIsBackslash
 					setTimeout () =>
 					setTimeout () =>
 						@editor.execCommand("startAutocomplete")
 						@editor.execCommand("startAutocomplete")
 					, 0
 					, 0
 			if (
 			if (
 				change.action == "insert" and
 				change.action == "insert" and
-				change.lines[0].match(/\\(\w+){}/)?[1].match(/(begin|[a-z]*ref|usepackage|[a-z]*cite[a-z]*)/)
+				change.lines[0].match(/\\(\w+){}/)?[1].match(
+					/(begin|end|[a-z]*ref|usepackage|[a-z]*cite[a-z]*|input|include)/
+				)
 			)
 			)
 				setTimeout () =>
 				setTimeout () =>
 					@editor.execCommand("startAutocomplete")
 					@editor.execCommand("startAutocomplete")
@@ -206,7 +208,7 @@ define [
 
 
 					# If we are in \begin{it|}, then we need to remove the trailing }
 					# If we are in \begin{it|}, then we need to remove the trailing }
 					# since it will be adding in with the autocomplete of \begin{item}...
 					# since it will be adding in with the autocomplete of \begin{item}...
-					if this.completions.filterText.match(/^\\begin\{/) and nextChar == "}"
+					if this.completions.filterText.match(/^\\\w+{/) and nextChar == "}"
 						editor.session.remove(range)
 						editor.session.remove(range)
 
 
 					# Provide our own `insertMatch` implementation.
 					# Provide our own `insertMatch` implementation.

+ 0 - 4
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee

@@ -160,14 +160,10 @@ define () ->
 
 
 	hasDocumentEnvironment = (text) ->
 	hasDocumentEnvironment = (text) ->
 		re = /^\\begin{document}/m
 		re = /^\\begin{document}/m
-		envs = []
-		iterations = 0
 		return re.exec(text) != null
 		return re.exec(text) != null
 
 
 	hasBibliographyEnvironment = (text) ->
 	hasBibliographyEnvironment = (text) ->
 		re = /^\\begin{thebibliography}/m
 		re = /^\\begin{thebibliography}/m
-		envs = []
-		iterations = 0
 		return re.exec(text) != null
 		return re.exec(text) != null
 
 
 	class EnvironmentManager
 	class EnvironmentManager

+ 1 - 4
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee

@@ -33,14 +33,11 @@ define [
 			commandName = Helpers.getCommandNameFromFragment(commandFragment)
 			commandName = Helpers.getCommandNameFromFragment(commandFragment)
 			beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999)
 			beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999)
 			lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
 			lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
-			needsClosingBrace = !lineBeyondCursor.match(/^[^{]*}/)
-			closingBrace = if needsClosingBrace then '}' else ''
 			return {
 			return {
 				lineUpToCursor,
 				lineUpToCursor,
 				commandFragment,
 				commandFragment,
 				commandName,
 				commandName,
-				lineBeyondCursor,
-				closingBrace
+				lineBeyondCursor
 			}
 			}
 
 
 	return Helpers
 	return Helpers

+ 3 - 6
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/PackageManager.coffee

@@ -1,6 +1,4 @@
-define [
-	"./Helpers"
-], (Helpers) ->
+define [], () ->
 	packages = [
 	packages = [
 		'inputenc', 'graphicx', 'amsmath', 'geometry', 'amssymb', 'hyperref',
 		'inputenc', 'graphicx', 'amsmath', 'geometry', 'amssymb', 'hyperref',
 		'babel', 'color', 'xcolor', 'url', 'natbib', 'fontenc', 'fancyhdr',
 		'babel', 'color', 'xcolor', 'url', 'natbib', 'fontenc', 'fancyhdr',
@@ -26,14 +24,13 @@ define [
 		constructor: (@metadataManager) ->
 		constructor: (@metadataManager) ->
 
 
 		getCompletions: (editor, session, pos, prefix, callback) ->
 		getCompletions: (editor, session, pos, prefix, callback) ->
-			{closingBrace} = Helpers.getContext(editor, pos)
 			usedPackages = Object.keys(@metadataManager.getAllPackages())
 			usedPackages = Object.keys(@metadataManager.getAllPackages())
 			packageSnippets = []
 			packageSnippets = []
 			for pkg in packages
 			for pkg in packages
 				if pkg not in usedPackages
 				if pkg not in usedPackages
 					packageSnippets.push {
 					packageSnippets.push {
-						caption: "\\usepackage{#{pkg}#{closingBrace}"
-						snippet: "\\usepackage{#{pkg}#{closingBrace}"
+						caption: "\\usepackage{#{pkg}}"
+						snippet: "\\usepackage{#{pkg}}"
 						meta: "pkg"
 						meta: "pkg"
 					}
 					}