From 5f40012af2a32558b005bb258fd72b412fb4d219 Mon Sep 17 00:00:00 2001 From: Franco Pariani <franco19ps@gmail.com> Date: Tue, 19 Feb 2019 22:51:31 -0300 Subject: [PATCH] Adding default functions --- .../layout/matefun/codemirror/hint_words.js | 14 ++++++ .../matefun/codemirror/matefun-mode-EN.js | 43 +++++++------------ Frontend Angular 4/src/styles/hints.css | 4 ++ 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Frontend Angular 4/src/app/layout/matefun/codemirror/hint_words.js b/Frontend Angular 4/src/app/layout/matefun/codemirror/hint_words.js index 43a436e4..232f3d17 100644 --- a/Frontend Angular 4/src/app/layout/matefun/codemirror/hint_words.js +++ b/Frontend Angular 4/src/app/layout/matefun/codemirror/hint_words.js @@ -8,6 +8,17 @@ let EN_default_sets = [ 'R', 'Color', 'Fig', 'A', 'Fig3D' ] +let EN_typed_functions = [ + '- :: R -> R', 'round :: R -> R', 'sin :: R -> R', 'cos :: R -> R', 'squareroot :: R -> R', + 'rgb :: (R X R X R) -> Color', 'rect :: (R X R) -> Fig', 'circ :: R -> Fig', 'line :: ((R X R) X (R X R)) -> Fig', + 'poli :: (R X R)* -> Fig', 'join :: (Fig X Fig) -> Fig', 'color :: (Fig X Color) -> Fig', 'move :: (Fig X (R X R)) -> Fig', + 'rotate :: (Fig X R) -> Fig', 'scale :: (Fig X R) -> Fig', 'toFig :: A -> Fig', 'line3D :: ((R X R X R) X (R X R X R)) -> Fig3D', + 'sphere :: R -> Fig3D', 'cylinder :: (R X R X R) -> Fig3D', 'cube :: (R X R X R) -> Fig3D', 'ring :: (R X R X R) -> Fig3D', + 'join3D :: (Fig3D X Fig3D) -> Fig3D', 'color3D :: (Fig3D X Color) -> Fig3D', 'move3D :: (Fig3D X (R X R X R)) -> Fig3D', + 'rotate3D :: (Fig3D X (R X R X R)) -> Fig3D', 'scale3D :: (Fig3D X R) -> Fig3D', 'range :: (R X R X R) -> R*', + 'first :: A* -> A', 'rest :: A* -> A*' +] + // Spanish words let ES_functions = [ @@ -25,6 +36,9 @@ module.exports = { EN_functions: function() { return EN_functions; }, + EN_typed_functions: function() { + return EN_typed_functions; + }, ES_default_sets: function() { return ES_default_sets; }, diff --git a/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js b/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js index 6e6efacc..56fc0271 100644 --- a/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js +++ b/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js @@ -205,11 +205,14 @@ elt.className = className; if (cur.render) cur.render(elt, data, cur); else { - elt.appendChild(ownerDocument.createTextNode("Function typing \n\n")); + var title = ownerDocument.createElement("p"); + title.className = "function-definition-title"; + title.appendChild(ownerDocument.createTextNode("Function typing \n")); + elt.appendChild(title); var rexp_name = new RegExp(/(.*\:\:)(.*)/.source, "g"); var m = rexp_name.exec(cur.displayText || getText(cur)); var b_elem = ownerDocument.createElement("b"); - b_elem.appendChild(ownerDocument.createTextNode(completion.filename + '.' + m[1])); + b_elem.appendChild(ownerDocument.createTextNode((hintWords.EN_typed_functions().indexOf(m[1] + m[2]) == -1 ? (completion.filename + '.') : "") + m[1])); elt.appendChild(b_elem); elt.appendChild(ownerDocument.createTextNode(m[2])); } @@ -409,8 +412,6 @@ if (found.length) return {list: found, from: from, to: to}; }); - //CodeMirror.commands.autocomplete = CodeMirror.showHint; - var defaultOptions = { hint: CodeMirror.hint.auto, completeSingle: true, @@ -422,8 +423,6 @@ customKeys: null, extraKeys: null }; - - //CodeMirror.defineOption("hintOptions", null); var WORD = /[\w$]+/; var RANGE = 500; @@ -431,7 +430,7 @@ var SET = /set\s+([\w\_\d]+)\s*\=/; var DOM = /\:\:/; var FUNS = /([\w\_\d]+)\s+\:\:/; - var COMPLETE_FUNS = /([\w\_\d]+)(\s+\:\:.*)/; + var COMPLETE_FUNS = /([\w\_\d\-]+)(\s+\:\:.*)/; var FUN = /([\w\_\d]+)\s*\(([\,\w\_\s\d]*)\)\s*\=/; var ENUMS = /set\s+[\w\_\d]+\s*\=\s*\{(.*?)\}/; var WRITING_SET = /set\s/; @@ -443,7 +442,6 @@ options = parseOptions(this, this.getCursor("start"), options); if (this.state.completionActive) this.state.completionActive.close(); var completion = this.state.completionActive = new Completion(this, options, filename); - //if (!completion.options.hint) return; CodeMirror.signal(this, "startFunctionDefinition", this); completion.update(true); @@ -480,29 +478,18 @@ } } - console.log(list); + // add default functions + var default_functions = hintWords.EN_typed_functions(); + for (var i = 0; i < default_functions.length; i++) { + re_funs = new RegExp(COMPLETE_FUNS.source, "g"); + var m = re_funs.exec(default_functions[i]); + if (m[1] == curWord) { + list.push(m[1] + m[2]); + } + } return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)}; } - /*options = parseOptions(this, this.getCursor("start"), options); - var selections = this.listSelections() - if (selections.length > 1) return; - //By default, don't allow completion when something is selected. - //A hint function can have a `supportsSelection` property to - //indicate that it can handle selections. - if (this.somethingSelected()) { - if (!options.hint.supportsSelection) return; - Don't try with cross-line selections - for (var i = 0; i < selections.length; i++) - if (selections[i].head.line != selections[i].anchor.line) return; - } - - if (this.state.completionActive) this.state.completionActive.close(); - var completion = this.state.completionActive = new Completion(this, options); - if (!completion.options.hint) return; - - CodeMirror.signal(this, "startCompletion", this); - completion.update(true);*/ }; // hints diff --git a/Frontend Angular 4/src/styles/hints.css b/Frontend Angular 4/src/styles/hints.css index b6511c01..c036deff 100644 --- a/Frontend Angular 4/src/styles/hints.css +++ b/Frontend Angular 4/src/styles/hints.css @@ -35,6 +35,10 @@ cursor: default; } +.function-definition-title { + color: goldenrod; +} + li.CodeMirror-hint-active { background: rgb(21, 117, 226) !important; color: white; -- GitLab