From 769875c5d53f873bba91ffca0e8cffa95f7505ac Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Thu, 3 Aug 2017 16:31:46 +0100 Subject: [PATCH 1/7] Adding default autocomplete commands w/ argument options --- .../auto-complete/AutoCompleteManager.coffee | 11 ++- .../StaticSuggestionManager.coffee | 81 +++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee 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 c320266a5a..fc164176a3 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 @@ -1,9 +1,10 @@ define [ "ide/editor/directives/aceEditor/auto-complete/SuggestionManager" "ide/editor/directives/aceEditor/auto-complete/SnippetManager" + "ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager" "ace/ace" "ace/ext-language_tools" -], (SuggestionManager, SnippetManager) -> +], (SuggestionManager, SnippetManager, StaticSuggestionManager) -> Range = ace.require("ace/range").Range aceSnippetManager = ace.require('ace/snippets').snippetManager @@ -44,6 +45,8 @@ define [ SnippetCompleter = new SnippetManager() + StaticCommandCompleter = new StaticSuggestionManager() + labelsManager = @labelsManager LabelsCompleter = getCompletions: (editor, session, pos, prefix, callback) -> @@ -112,7 +115,11 @@ define [ else callback null, result - @editor.completers = [@suggestionManager, SnippetCompleter, ReferencesCompleter, LabelsCompleter] + @editor.completers = [@suggestionManager, + SnippetCompleter, + StaticCommandCompleter, + ReferencesCompleter, + LabelsCompleter] disable: () -> @editor.setOptions({ diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee new file mode 100644 index 0000000000..df5153a833 --- /dev/null +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee @@ -0,0 +1,81 @@ +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 = ['def', 'let', 'LaTeX'] + + 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 com in special + if com == 'def' + { #should be improved + caption: "\\def{}" + snippet: "\\def$1{$2}" + meta: "cmd" + } + else if com == 'let' + { #should be improved + caption: "\\let" + snippet: "\\let" + meta: "cmd" + } + else if com == 'LaTeX' + { + caption: "\\LaTeX{}" + snippet: "\\LaTeX{}" + meta: "cmd" + } + + staticCommands = [].concat(noArgumentCommands, + singleArgumentCommands, + doubleArgumentCommands, + tripleArgumentCommands, + special) + + class StaticSuggestionManager + getCompletions: (editor, session, pos, prefix, callback) -> + callback null, staticCommands + + return StaticSuggestionManager From 688f1e9e753cbe64040338a19773009dc88fa6e9 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Fri, 11 Aug 2017 09:23:36 +0100 Subject: [PATCH 2/7] merged staticManager with snippetManager --- .../auto-complete/AutoCompleteManager.coffee | 6 +- .../auto-complete/SnippetManager.coffee | 85 ++++++++++++++++++- .../StaticSuggestionManager.coffee | 81 ------------------ 3 files changed, 84 insertions(+), 88 deletions(-) delete mode 100644 services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee 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 fc164176a3..5b02c6b6bb 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 @@ -1,10 +1,9 @@ define [ "ide/editor/directives/aceEditor/auto-complete/SuggestionManager" "ide/editor/directives/aceEditor/auto-complete/SnippetManager" - "ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager" "ace/ace" "ace/ext-language_tools" -], (SuggestionManager, SnippetManager, StaticSuggestionManager) -> +], (SuggestionManager, SnippetManager) -> Range = ace.require("ace/range").Range aceSnippetManager = ace.require('ace/snippets').snippetManager @@ -45,8 +44,6 @@ define [ SnippetCompleter = new SnippetManager() - StaticCommandCompleter = new StaticSuggestionManager() - labelsManager = @labelsManager LabelsCompleter = getCompletions: (editor, session, pos, prefix, callback) -> @@ -117,7 +114,6 @@ define [ @editor.completers = [@suggestionManager, SnippetCompleter, - StaticCommandCompleter, ReferencesCompleter, LabelsCompleter] diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index 7b7593565d..7927a2cd6f 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -1,4 +1,73 @@ 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 = [ "abstract", "align", "align*", @@ -6,7 +75,9 @@ define () -> "gather", "gather*", "multline", "multline*", "split", - "verbatim" + "verbatim", + "quote", + "center" ] staticSnippets = for env in environments @@ -95,7 +166,17 @@ define () -> \\end{frame} """ meta: "env" - }] + }, { + caption: "\\begin{thebibliography}..." + snippet: """ + \\begin{thebibliography}{$1} + \\bibitem{$2} + $3 + \\end{thebibliography} + """ + }] + + staticSnippets = staticSnippets.concat staticCommands parseCustomEnvironments = (text) -> diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee deleted file mode 100644 index df5153a833..0000000000 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/StaticSuggestionManager.coffee +++ /dev/null @@ -1,81 +0,0 @@ -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 = ['def', 'let', 'LaTeX'] - - 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 com in special - if com == 'def' - { #should be improved - caption: "\\def{}" - snippet: "\\def$1{$2}" - meta: "cmd" - } - else if com == 'let' - { #should be improved - caption: "\\let" - snippet: "\\let" - meta: "cmd" - } - else if com == 'LaTeX' - { - caption: "\\LaTeX{}" - snippet: "\\LaTeX{}" - meta: "cmd" - } - - staticCommands = [].concat(noArgumentCommands, - singleArgumentCommands, - doubleArgumentCommands, - tripleArgumentCommands, - special) - - class StaticSuggestionManager - getCompletions: (editor, session, pos, prefix, callback) -> - callback null, staticCommands - - return StaticSuggestionManager From 6e9b1c602be44071ad1636df876c0bd4ad91b3e4 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Mon, 14 Aug 2017 18:02:51 +0100 Subject: [PATCH 3/7] fixing spaces vs. tabs issue --- .../auto-complete/AutoCompleteManager.coffee | 10 +- .../auto-complete/SnippetManager.coffee | 134 +++++++++--------- 2 files changed, 74 insertions(+), 70 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 5b02c6b6bb..e8893bf786 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 @@ -112,10 +112,12 @@ define [ else callback null, result - @editor.completers = [@suggestionManager, - SnippetCompleter, - ReferencesCompleter, - LabelsCompleter] + @editor.completers = [ + @suggestionManager, + SnippetCompleter, + ReferencesCompleter, + LabelsCompleter + ] disable: () -> @editor.setOptions({ diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index 7927a2cd6f..abc27badf9 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -1,72 +1,74 @@ 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'] + '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" - } + 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) + staticCommands = [].concat( + noArgumentCommands, + singleArgumentCommands, + doubleArgumentCommands, + tripleArgumentCommands, + special + ) environments = [ "abstract", @@ -174,7 +176,7 @@ define () -> $3 \\end{thebibliography} """ - }] + }] staticSnippets = staticSnippets.concat staticCommands From f253b7e8cbd74e7fc72d7ded424853c7f6d33532 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Wed, 16 Aug 2017 17:40:01 +0100 Subject: [PATCH 4/7] fixing command duplication issue during suggestion --- .../auto-complete/SnippetManager.coffee | 75 ------------ .../auto-complete/SuggestionManager.coffee | 111 +++++++++++++++--- 2 files changed, 92 insertions(+), 94 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index abc27badf9..6bbb25f59e 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -1,75 +1,4 @@ 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 = [ "abstract", "align", "align*", @@ -178,9 +107,6 @@ define () -> """ }] - staticSnippets = staticSnippets.concat staticCommands - - parseCustomEnvironments = (text) -> re = /^\\newenvironment{(\w+)}.*$/gm result = [] @@ -192,7 +118,6 @@ define () -> return result return result - parseBeginCommands = (text) -> re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm result = [] diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee index 250590e4b4..a139f8fa8c 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee @@ -1,4 +1,75 @@ 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 constructor: (@doc, @prefix) -> @@ -95,26 +166,28 @@ define [], () -> commands = parser.parse() completions = [] 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 - } + 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 + callback(null, completions) loadCommandsFromDoc: (doc) -> parser = new Parser(doc) From d1b906db43d85cbc2ab1433d522d5d00834eba12 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Wed, 16 Aug 2017 17:55:43 +0100 Subject: [PATCH 5/7] renaming and organizing --- .../aceEditor/auto-complete/AutoCompleteManager.coffee | 10 +++++----- ...{SuggestionManager.coffee => CommandManager.coffee} | 2 +- ...SnippetManager.coffee => EnvironmentManager.coffee} | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/{SuggestionManager.coffee => CommandManager.coffee} (99%) rename services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/{SnippetManager.coffee => EnvironmentManager.coffee} (98%) 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 e8893bf786..4466f200c6 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 @@ -1,9 +1,9 @@ define [ - "ide/editor/directives/aceEditor/auto-complete/SuggestionManager" - "ide/editor/directives/aceEditor/auto-complete/SnippetManager" + "ide/editor/directives/aceEditor/auto-complete/CommandManager" + "ide/editor/directives/aceEditor/auto-complete/EnvironmentManager" "ace/ace" "ace/ext-language_tools" -], (SuggestionManager, SnippetManager) -> +], (CommandManager, EnvironmentManager) -> Range = ace.require("ace/range").Range aceSnippetManager = ace.require('ace/snippets').snippetManager @@ -18,7 +18,7 @@ define [ class AutoCompleteManager constructor: (@$scope, @editor, @element, @labelsManager) -> - @suggestionManager = new SuggestionManager() + @suggestionManager = new CommandManager() @monkeyPatchAutocomplete() @@ -42,7 +42,7 @@ define [ enableLiveAutocompletion: false }) - SnippetCompleter = new SnippetManager() + SnippetCompleter = new EnvironmentManager() labelsManager = @labelsManager LabelsCompleter = diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/CommandManager.coffee similarity index 99% rename from services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee rename to services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/CommandManager.coffee index a139f8fa8c..0a202a7793 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/CommandManager.coffee @@ -159,7 +159,7 @@ define [], () -> else return false - class SuggestionManager + class CommandManager getCompletions: (editor, session, pos, prefix, callback) -> doc = session.getValue() parser = new Parser(doc, prefix) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee similarity index 98% rename from services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee rename to services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee index 6bbb25f59e..04152cfbd9 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee @@ -129,7 +129,7 @@ define () -> return result return result - class SnippetManager + class EnvironmentManager getCompletions: (editor, session, pos, prefix, callback) -> docText = session.getValue() customEnvironments = parseCustomEnvironments(docText) @@ -164,4 +164,4 @@ define () -> ) callback null, snippets - return SnippetManager + return EnvironmentManager From 42be1164bc34052ec12d789856b061de1508b73e Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Thu, 17 Aug 2017 14:30:18 +0100 Subject: [PATCH 6/7] fixing environment duplication in autocomplete issue --- .../auto-complete/EnvironmentManager.coffee | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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 04152cfbd9..4ed1d7b713 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 @@ -11,6 +11,20 @@ define () -> "center" ] + snippetNames = [ + "array", + "figure", + "tabular", + "table", + "list", + "enumerate", + "itemize", + "frame", + "thebibliography" + ] + + environmentNames = snippetNames.concat environments + staticSnippets = for env in environments { caption: "\\begin{#{env}}..." @@ -123,10 +137,11 @@ define () -> result = [] iterations = 0 while match = re.exec(text) - result.push {name: match[1], whitespace: match[2]} - iterations += 1 - if iterations >= 1000 - return result + if match[1] not in environmentNames + result.push {name: match[1], whitespace: match[2]} + iterations += 1 + if iterations >= 1000 + return result return result class EnvironmentManager From adb26b1b94890caf94030abd847ecd3f18a2be25 Mon Sep 17 00:00:00 2001 From: Nate Stemen Date: Fri, 18 Aug 2017 14:24:44 +0100 Subject: [PATCH 7/7] forgot meta tag for "thebibiography" --- .../directives/aceEditor/auto-complete/EnvironmentManager.coffee | 1 + 1 file changed, 1 insertion(+) 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 4ed1d7b713..8208ec4a30 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 @@ -119,6 +119,7 @@ define () -> $3 \\end{thebibliography} """ + meta: "env" }] parseCustomEnvironments = (text) ->