From e7038f0a579c969162c1184e36a4be55e495c6bf Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Mon, 18 Jun 2018 15:08:25 -0400 Subject: [PATCH] remove trailing } for all commands rather than relying on Helpers module --- .../auto-complete/AutoCompleteManager.coffee | 40 ++++++++++--------- .../auto-complete/EnvironmentManager.coffee | 4 -- .../aceEditor/auto-complete/Helpers.coffee | 5 +-- .../auto-complete/PackageManager.coffee | 9 ++--- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index 160c28bd1e..638ab20b30 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -44,11 +44,11 @@ define [ GraphicsCompleter = getCompletions: (editor, session, pos, prefix, callback) -> - {commandFragment, closingBrace} = Helpers.getContext(editor, pos) + {commandFragment} = Helpers.getContext(editor, pos) if commandFragment match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/) if match - [commandName, _, currentArg] = match + [_, commandName, _, currentArg] = match graphicsPaths = Preamble.getGraphicsPaths() result = [] for graphic in Graphics.getGraphicsFiles() @@ -58,8 +58,8 @@ define [ path = path.slice(graphicsPath.length) break result.push { - caption: "\\#{commandName}{#{path}#{closingBrace}" - value: "\\#{commandName}{#{path}#{closingBrace}" + caption: "\\#{commandName}{#{path}}" + value: "\\#{commandName}{#{path}}" meta: "graphic" score: 50 } @@ -68,18 +68,18 @@ define [ metadataManager = @metadataManager FilesCompleter = getCompletions: (editor, session, pos, prefix, callback) => - {commandFragment, closingBrace} = Helpers.getContext(editor, pos) + {commandFragment} = Helpers.getContext(editor, pos) if commandFragment match = commandFragment.match(/^\\(input|include){(\w*)/) if match - [commandName, currentArg] = match + [_, commandName, currentArg] = match result = [] for file in Files.getTeXFiles() if file.id != @$scope.docId path = file.path result.push { - caption: "\\#{commandName}{#{path}#{closingBrace}" - value: "\\#{commandName}{#{path}#{closingBrace}" + caption: "\\#{commandName}{#{path}}" + value: "\\#{commandName}{#{path}}" meta: "file" score: 50 } @@ -87,11 +87,11 @@ define [ LabelsCompleter = getCompletions: (editor, session, pos, prefix, callback) -> - {commandFragment, closingBrace} = Helpers.getContext(editor, pos) + {commandFragment} = Helpers.getContext(editor, pos) if commandFragment refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/) if refMatch - [commandName, currentArg] = refMatch + [_, commandName, currentArg] = refMatch result = [] if commandName != 'ref' # ref is in top 100 commands result.push { @@ -102,8 +102,8 @@ define [ } for label in metadataManager.getAllLabels() result.push { - caption: "\\#{commandName}{#{label}#{closingBrace}" - value: "\\#{commandName}{#{label}#{closingBrace}" + caption: "\\#{commandName}{#{label}}" + value: "\\#{commandName}{#{label}}" meta: "cross-reference" score: 50 } @@ -112,13 +112,13 @@ define [ references = @$scope.$root._references ReferencesCompleter = getCompletions: (editor, session, pos, prefix, callback) -> - {commandFragment, closingBrace} = Helpers.getContext(editor, pos) + {commandFragment} = Helpers.getContext(editor, pos) if commandFragment citeMatch = commandFragment.match( /^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/ ) if citeMatch - [commandName, previousArgs, currentArg] = citeMatch + [_, commandName, previousArgs, currentArg] = citeMatch if !previousArgs? previousArgs = "" previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs @@ -133,8 +133,8 @@ define [ references.keys.forEach (key) -> if key? result.push({ - caption: "\\#{commandName}{#{previousArgsCaption}#{key}#{closingBrace}" - value: "\\#{commandName}{#{previousArgs}#{key}#{closingBrace}" + caption: "\\#{commandName}{#{previousArgsCaption}#{key}}" + value: "\\#{commandName}{#{previousArgs}#{key}}" meta: "reference" score: 50 }) @@ -178,13 +178,15 @@ define [ end.row == cursorPosition.row and end.column == cursorPosition.column + 1 ) - if (commandFragment? and commandFragment.length > 2) or lastCharIsBackslash + if commandFragment?.length > 2 or lastCharIsBackslash setTimeout () => @editor.execCommand("startAutocomplete") , 0 if ( 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 () => @editor.execCommand("startAutocomplete") @@ -206,7 +208,7 @@ define [ # 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}... - if this.completions.filterText.match(/^\\begin\{/) and nextChar == "}" + if this.completions.filterText.match(/^\\\w+{/) and nextChar == "}" editor.session.remove(range) # Provide our own `insertMatch` implementation. diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee index 383bf1bd2e..156389e73d 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee @@ -160,14 +160,10 @@ define () -> hasDocumentEnvironment = (text) -> re = /^\\begin{document}/m - envs = [] - iterations = 0 return re.exec(text) != null hasBibliographyEnvironment = (text) -> re = /^\\begin{thebibliography}/m - envs = [] - iterations = 0 return re.exec(text) != null class EnvironmentManager diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee index 87a41f06d3..c8bcbdb6ab 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Helpers.coffee @@ -33,14 +33,11 @@ define [ commandName = Helpers.getCommandNameFromFragment(commandFragment) beyondCursorRange = new Range(pos.row, pos.column, pos.row, 99999) lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange) - needsClosingBrace = !lineBeyondCursor.match(/^[^{]*}/) - closingBrace = if needsClosingBrace then '}' else '' return { lineUpToCursor, commandFragment, commandName, - lineBeyondCursor, - closingBrace + lineBeyondCursor } return Helpers diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/PackageManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/PackageManager.coffee index 4ab1b6933c..12bcc26a8f 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/PackageManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/PackageManager.coffee @@ -1,6 +1,4 @@ -define [ - "./Helpers" -], (Helpers) -> +define [], () -> packages = [ 'inputenc', 'graphicx', 'amsmath', 'geometry', 'amssymb', 'hyperref', 'babel', 'color', 'xcolor', 'url', 'natbib', 'fontenc', 'fancyhdr', @@ -26,14 +24,13 @@ define [ constructor: (@metadataManager) -> getCompletions: (editor, session, pos, prefix, callback) -> - {closingBrace} = Helpers.getContext(editor, pos) usedPackages = Object.keys(@metadataManager.getAllPackages()) packageSnippets = [] for pkg in packages if pkg not in usedPackages packageSnippets.push { - caption: "\\usepackage{#{pkg}#{closingBrace}" - snippet: "\\usepackage{#{pkg}#{closingBrace}" + caption: "\\usepackage{#{pkg}}" + snippet: "\\usepackage{#{pkg}}" meta: "pkg" }