From 158ff94c41010329a8850978faa15e9d5b915219 Mon Sep 17 00:00:00 2001 From: marmoure Date: Mon, 30 May 2022 20:47:29 +0200 Subject: [PATCH 01/10] disable auto pairing in all cases --- src/ace-modes.js | 1020 ++++++++++++++++++++++++---------------------- 1 file changed, 531 insertions(+), 489 deletions(-) diff --git a/src/ace-modes.js b/src/ace-modes.js index 8772ae39..1b4f58cf 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -18,463 +18,310 @@ */ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { -var oop = require("ace/lib/oop"); -var lang = require("ace/lib/lang"); -var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules; - -var XQueryHighlightRules = function() { - - var keywords = lang.arrayToMap( - ("return|for|let|where|order|by|declare|function|variable|xquery|version|option|namespace|import|module|" + - "switch|default|map|" + - "if|then|else|as|and|or|typeswitch|case|ascending|descending|empty|in").split("|") - ); - - // regexp must not have capturing parentheses - // regexps are ordered -> the first match is used - - this.$rules = { - start : [ { - token : "text", - regex : "<\\!\\[CDATA\\[", - next : "cdata" - }, { - token : "xml_pe", - regex : "<\\?.*?\\?>" - }, { - token : "comment", - regex : "<\\!--", - next : "comment" - }, { - token : "comment", - regex : "\\(:", - next : "comment" - }, { - token : "text", // opening tag - regex : "<\\/?", - next : "tag" - }, { - token : "constant", // number - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : "variable", // variable - regex : "\\$[a-zA-Z_][a-zA-Z0-9_\\-:]*\\b" - }, { - token: "string", - regex : '".*?"' - }, { - token: "string", - regex : "'.*?'" - }, { - token : "text", - regex : "\\s+" - }, { - token: "comment", - regex: "\\%\\w[\\w+_\\-:]+\\b" - }, { - token: "support.function", - regex: "\\w[\\w+_\\-:]+(?=\\()" - }, { - token: "keyword.operator", - regex: "\\*|=|<|>|\\-|\\+|and|or|eq|ne|lt|gt" - }, { - token: "lparen", - regex: "[[({]" - }, { - token: "rparen", - regex: "[\\])}]" - }, { - token : function(value) { - if (keywords[value]) - return "keyword"; - else - return "identifier"; - }, - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - } ], - - tag : [ { - token : "text", - regex : ">", - next : "start" - }, { - token : "keyword", - regex : "[-_a-zA-Z0-9:]+" - }, { - token : "text", - regex : "\\s+" - }, { - token : "string", - regex : '".*?"' - }, { - token : "string", - regex : "'.*?'" - } ], - - cdata : [ { - token : "text", - regex : "\\]\\]>", - next : "start" - }, { - token : "text", - regex : "\\s+" - }, { - token : "text", - regex : "(?:[^\\]]|\\](?!\\]>))+" - } ], - - comment : [ { - token : "comment", - regex : ".*?-->", - next : "start" - }, { - token: "comment", - regex : ".*:\\)", - next : "start" - }, { - token : "comment", - regex : ".+" - } ] + var oop = require("ace/lib/oop"); + var lang = require("ace/lib/lang"); + var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules; + + var XQueryHighlightRules = function() { + + var keywords = lang.arrayToMap( + ("return|for|let|where|order|by|declare|function|variable|xquery|version|option|namespace|import|module|" + + "switch|default|map|" + + "if|then|else|as|and|or|typeswitch|case|ascending|descending|empty|in").split("|") + ); + + // regexp must not have capturing parentheses + // regexps are ordered -> the first match is used + + this.$rules = { + start : [ { + token : "text", + regex : "<\\!\\[CDATA\\[", + next : "cdata" + }, { + token : "xml_pe", + regex : "<\\?.*?\\?>" + }, { + token : "comment", + regex : "<\\!--", + next : "comment" + }, { + token : "comment", + regex : "\\(:", + next : "comment" + }, { + token : "text", // opening tag + regex : "<\\/?", + next : "tag" + }, { + token : "constant", // number + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "variable", // variable + regex : "\\$[a-zA-Z_][a-zA-Z0-9_\\-:]*\\b" + }, { + token: "string", + regex : '".*?"' + }, { + token: "string", + regex : "'.*?'" + }, { + token : "text", + regex : "\\s+" + }, { + token: "comment", + regex: "\\%\\w[\\w+_\\-:]+\\b" + }, { + token: "support.function", + regex: "\\w[\\w+_\\-:]+(?=\\()" + }, { + token: "keyword.operator", + regex: "\\*|=|<|>|\\-|\\+|and|or|eq|ne|lt|gt" + }, { + token: "lparen", + regex: "[[({]" + }, { + token: "rparen", + regex: "[\\])}]" + }, { + token : function(value) { + if (keywords[value]) + return "keyword"; + else + return "identifier"; + }, + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + } ], + + tag : [ { + token : "text", + regex : ">", + next : "start" + }, { + token : "keyword", + regex : "[-_a-zA-Z0-9:]+" + }, { + token : "text", + regex : "\\s+" + }, { + token : "string", + regex : '".*?"' + }, { + token : "string", + regex : "'.*?'" + } ], + + cdata : [ { + token : "text", + regex : "\\]\\]>", + next : "start" + }, { + token : "text", + regex : "\\s+" + }, { + token : "text", + regex : "(?:[^\\]]|\\](?!\\]>))+" + } ], + + comment : [ { + token : "comment", + regex : ".*?-->", + next : "start" + }, { + token: "comment", + regex : ".*:\\)", + next : "start" + }, { + token : "comment", + regex : ".+" + } ] + }; }; -}; - -oop.inherits(XQueryHighlightRules, TextHighlightRules); - -exports.XQueryHighlightRules = XQueryHighlightRules; -}); - -define("eXide/mode/behaviour/xquery", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var Behaviour = require('ace/mode/behaviour').Behaviour; - var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; - - var XQueryBehaviour = function (parent) { - - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour - this.parent = parent; - - this.add("brackets", "insertion", function (state, action, editor, session, text) { - if (text == "\n") { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChars = line.substring(cursor.column, cursor.column + 2); - // check if pressed enter between two tags and increase indent automatically - if (rightChars == ' 0 && line.charAt(cursor.column - 1) == "<") { + line = line.substring(0, cursor.column) + '/' + line.substring(cursor.column + 1, line.length); + var lines = session.doc.getAllLines(); + lines[cursor.row] = line; + // call mode helper to close the tag if possible + parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); + } + } + return false; + }); + + this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { + if (text == "\"") { return { - text: '\n' + " : ", - selection: [1, 3, 1, 3] + text: "\"", + selection: [] } } - } - if (text == ":") { - var leftChar = line.substring(cursor.column - 1, 1); - if (leftChar == "(") { + return false; + }); + + this.add("parens", "insertion", function (state, action, editor, session, text) { + if (text == "(") { return { - text: ": :", - selection: [2, 2] + text: "(", + selection: [] } } - } - }); - - // Check for open tag if user enters / and auto-close it. - this.add("slash", "insertion", function (state, action, editor, session, text) { - if (text == "/") { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - if (cursor.column > 0 && line.charAt(cursor.column - 1) == "<") { - line = line.substring(0, cursor.column) + '/' + line.substring(cursor.column + 1, line.length); - var lines = session.doc.getAllLines(); - lines[cursor.row] = line; - // call mode helper to close the tag if possible - parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); - } - } - return false; - }); - } - oop.inherits(XQueryBehaviour, Behaviour); - - exports.XQueryBehaviour = XQueryBehaviour; -}); - -define("eXide/mode/xquery", function(require, exports, module) { - -var oop = require("ace/lib/oop"); -var TextMode = require("ace/mode/text").Mode; -var XQueryLexer = require("lib/XQueryLexer").XQueryLexer; - -var Tokenizer = require("ace/tokenizer").Tokenizer; -var XQueryBehaviour = require("eXide/mode/behaviour/xquery").XQueryBehaviour; -var CStyleFoldMode = require("ace/mode/folding/cstyle").FoldMode; -var Range = require("ace/range").Range; - -var Mode = function(parent) { - this.$tokenizer = new XQueryLexer(); - this.$behaviour = new XQueryBehaviour(parent); - this.foldingRules = new CStyleFoldMode(); -}; - -oop.inherits(Mode, TextMode); - -(function() { - - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/); - if (match) - indent += tab; - return indent; - }; + return false; + }); - this.checkOutdent = function(state, line, input) { - if (! /^\s+$/.test(line)) - return false; - - return /^\s*[\}\)]/.test(input); - }; + this.add("braces", "insertion", function (state, action, editor, session, text) { + if (text == "{") { + return { + text: "{", + selection: [] + } + } + return false; + }); - this.autoOutdent = function(state, doc, row) { - var line = doc.getLine(row); - var match = line.match(/^(\s*[\}\)])/); - - if (!match) return 0; - - var column = match[1].length; - var openBracePos = doc.findMatchingBracket({row: row, column: column}); - - if (!openBracePos || openBracePos.row == row) return 0; - - var indent = this.$getIndent(doc.getLine(openBracePos.row)); - doc.replace(new Range(row, 0, row, column-1), indent); - }; - - this.$getIndent = function(line) { - var match = line.match(/^(\s+)/); - if (match) { - return match[1]; } - - return ""; - }; + oop.inherits(XQueryBehaviour, Behaviour); - this.toggleCommentLines = function(state, doc, startRow, endRow) { - var i, line; - var outdent = true; - var re = /^\s*\(:(.*):\)/; - - for (i=startRow; i<= endRow; i++) { - if (!re.test(doc.getLine(i))) { - outdent = false; - break; - } - } - - var range = new Range(0, 0, 0, 0); - for (i=startRow; i<= endRow; i++) { - line = doc.getLine(i); - range.start.row = i; - range.end.row = i; - range.end.column = line.length; - - doc.replace(range, outdent ? line.match(re)[1] : "(:" + line + ":)"); - } + exports.XQueryBehaviour = XQueryBehaviour; + }); + + define("eXide/mode/xquery", function(require, exports, module) { + + var oop = require("ace/lib/oop"); + var TextMode = require("ace/mode/text").Mode; + var XQueryLexer = require("lib/XQueryLexer").XQueryLexer; + + var Tokenizer = require("ace/tokenizer").Tokenizer; + var XQueryBehaviour = require("eXide/mode/behaviour/xquery").XQueryBehaviour; + var CStyleFoldMode = require("ace/mode/folding/cstyle").FoldMode; + var Range = require("ace/range").Range; + + var Mode = function(parent) { + this.$tokenizer = new XQueryLexer(); + this.$behaviour = new XQueryBehaviour(parent); + this.foldingRules = new CStyleFoldMode(); }; - /*this.createWorker = function(session) { - this.$deltas = []; - var worker = new WorkerClient(["ace"], "ace/mode/xquery_worker", "XQueryWorker"); - var that = this; - - session.getDocument().on('change', function(evt){ - that.$deltas.push(evt.data); - }); - - worker.attachToDocument(session.getDocument()); - - worker.on("start", function(e) { - that.$deltas = []; - }); - - worker.on("error", function(e) { - // errors are ignored because they are reported by eXist's compiler - }); - - worker.on("xqlint", function(e) { - var annotations = []; - for (var i = 0; i < e.data.length; i++) { - if (e.data[i].type !== "error") { - annotations.push({ - row: e.data[i].pos.sl, - text: e.data[i].message, - type: e.data[i].type - }); - } - } - session.setAnnotations(annotations); - }); - - worker.on("ok", function(e) { - session.clearAnnotations(); - }); + oop.inherits(Mode, TextMode); + + (function() { - worker.on("highlight", function(tokens) { - if(that.$deltas.length > 0) return; - - var firstRow = 0; - var lastRow = session.getLength() - 1; - - var lines = tokens.data.lines; - var states = tokens.data.states; - - session.bgTokenizer.lines = lines; - session.bgTokenizer.states = states; - session.bgTokenizer.fireUpdateEvent(firstRow, lastRow); - }); + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/); + if (match) + indent += tab; + return indent; + }; - return worker; - };*/ - -}).call(Mode.prototype); - -exports.Mode = Mode; -}); - -define("eXide/mode/behaviour/xml", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var Behaviour = require('ace/mode/behaviour').Behaviour; - var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; - var TokenIterator = require("ace/token_iterator").TokenIterator; - - function hasType(token, type) { - var hasType = true; - var typeList = token.type.split('.'); - var needleList = type.split('.'); - needleList.forEach(function(needle){ - if (typeList.indexOf(needle) == -1) { - hasType = false; + this.checkOutdent = function(state, line, input) { + if (! /^\s+$/.test(line)) return false; - } - }); - return hasType; - } - - var XMLBehaviour = function (parent) { - - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour - this.parent = parent; - - this.add("brackets", "insertion", function (state, action, editor, session, text) { - if (text == "\n") { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChars = line.substring(cursor.column, cursor.column + 2); - if (rightChars == ' 0 && line.charAt(cursor.column - 1) == "<") { - line = line.substring(0, cursor.column) + "/" + line.substring(cursor.column); - var lines = session.doc.getAllLines(); - lines[cursor.row] = line; - // call mode helper to close the tag if possible - parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); - } - } - return false; - }); + + return /^\s*[\}\)]/.test(input); + }; - this.add("autoclosing", "insertion", function (state, action, editor, session, text) { - if (text == '>') { - var position = editor.getCursorPosition(); - var iterator = new TokenIterator(session, position.row, position.column); - var token = iterator.getCurrentToken(); - var atCursor = false; - if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))){ - do { - token = iterator.stepBackward(); - } while (token && (hasType(token, 'string') || hasType(token, 'keyword.operator') || hasType(token, 'entity.attribute-name') || hasType(token, 'text'))); - } else { - atCursor = true; - } - if (!token || !hasType(token, 'meta.tag-name') || iterator.stepBackward().value.match('/')) { - return - } - var tag = token.value; - if (atCursor){ - var tag = tag.substring(0, position.column - token.start); - } + this.autoOutdent = function(state, doc, row) { + var line = doc.getLine(row); + var match = line.match(/^(\s*[\}\)])/); - return { - text: '>' + '', - selection: [1, 1] - } + if (!match) return 0; + + var column = match[1].length; + var openBracePos = doc.findMatchingBracket({row: row, column: column}); + + if (!openBracePos || openBracePos.row == row) return 0; + + var indent = this.$getIndent(doc.getLine(openBracePos.row)); + doc.replace(new Range(row, 0, row, column-1), indent); + }; + + this.$getIndent = function(line) { + var match = line.match(/^(\s+)/); + if (match) { + return match[1]; } - }); - } - oop.inherits(XMLBehaviour, Behaviour); - - exports.XMLBehaviour = XMLBehaviour; -}); - -define("eXide/mode/xml", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var XmlMode = require("ace/mode/xml").Mode; - var Tokenizer = require("ace/tokenizer").Tokenizer; - var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules; - var XmlFoldMode = require("ace/mode/folding/xml").FoldMode; - var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; - var Range = require("ace/range").Range; - - var Mode = function(parent) { - this.$tokenizer = new Tokenizer(new XmlHighlightRules().getRules()); - this.$behaviour = new XMLBehaviour(parent); - this.foldingRules = new XmlFoldMode(); - }; - - oop.inherits(Mode, XmlMode); - - (function() { + + return ""; + }; this.toggleCommentLines = function(state, doc, startRow, endRow) { var i, line; var outdent = true; - var re = /^\s*/; + var re = /^\s*\(:(.*):\)/; for (i=startRow; i<= endRow; i++) { if (!re.test(doc.getLine(i))) { @@ -490,67 +337,262 @@ define("eXide/mode/xml", function(require, exports, module) { range.end.row = i; range.end.column = line.length; - doc.replace(range, outdent ? line.match(re)[1] : ""); + doc.replace(range, outdent ? line.match(re)[1] : "(:" + line + ":)"); } }; - }).call(Mode.prototype); - - exports.Mode = Mode; -}); - -define("eXide/mode/html", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var HtmlMode = require("ace/mode/html").Mode; - var Tokenizer = require("ace/tokenizer").Tokenizer; - var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules; - var HtmlFoldMode = require("ace/mode/folding/html").FoldMode; - var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; - var Range = require("ace/range").Range; - var JavaScriptMode = require("ace/mode/javascript").Mode; - var CssMode = require("ace/mode/css").Mode; - - var Mode = function(parent) { - var highlighter = new HtmlHighlightRules(); - this.$tokenizer = new Tokenizer(highlighter.getRules()); - this.$behaviour = new XMLBehaviour(parent); - //this.$behaviour = new HtmlBehaviour(); - this.foldingRules = new HtmlFoldMode(); - this.$embeds = highlighter.getEmbeds(); - this.createModeDelegates({ - "js-": JavaScriptMode, - "css-": CssMode - }); - }; - - oop.inherits(Mode, HtmlMode); - - (function() { + /*this.createWorker = function(session) { + this.$deltas = []; + var worker = new WorkerClient(["ace"], "ace/mode/xquery_worker", "XQueryWorker"); + var that = this; + + session.getDocument().on('change', function(evt){ + that.$deltas.push(evt.data); + }); + + worker.attachToDocument(session.getDocument()); + + worker.on("start", function(e) { + that.$deltas = []; + }); + + worker.on("error", function(e) { + // errors are ignored because they are reported by eXist's compiler + }); + + worker.on("xqlint", function(e) { + var annotations = []; + for (var i = 0; i < e.data.length; i++) { + if (e.data[i].type !== "error") { + annotations.push({ + row: e.data[i].pos.sl, + text: e.data[i].message, + type: e.data[i].type + }); + } + } + session.setAnnotations(annotations); + }); + + worker.on("ok", function(e) { + session.clearAnnotations(); + }); + + worker.on("highlight", function(tokens) { + if(that.$deltas.length > 0) return; + + var firstRow = 0; + var lastRow = session.getLength() - 1; + + var lines = tokens.data.lines; + var states = tokens.data.states; + + session.bgTokenizer.lines = lines; + session.bgTokenizer.states = states; + session.bgTokenizer.fireUpdateEvent(firstRow, lastRow); + }); + + return worker; + };*/ - this.toggleCommentLines = function(state, doc, startRow, endRow) { - var i, line; - var outdent = true; - var re = /^\s*/; + }).call(Mode.prototype); - for (i=startRow; i<= endRow; i++) { - if (!re.test(doc.getLine(i))) { - outdent = false; - break; + exports.Mode = Mode; + }); + + define("eXide/mode/behaviour/xml", function(require, exports, module) { + + var oop = require("ace/lib/oop"); + var Behaviour = require('ace/mode/behaviour').Behaviour; + var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; + var TokenIterator = require("ace/token_iterator").TokenIterator; + + function hasType(token, type) { + var hasType = true; + var typeList = token.type.split('.'); + var needleList = type.split('.'); + needleList.forEach(function(needle){ + if (typeList.indexOf(needle) == -1) { + hasType = false; + return false; } - } + }); + return hasType; + } + + var XMLBehaviour = function (parent) { + + this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour + this.parent = parent; + + this.add("brackets", "insertion", function (state, action, editor, session, text) { + if (text == "\n") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChars = line.substring(cursor.column, cursor.column + 2); + if (rightChars == '"); - } + // Check for open tag if user enters / and auto-close it. + this.add("slash", "insertion", function (state, action, editor, session, text) { + if (text == "/") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + if (cursor.column > 0 && line.charAt(cursor.column - 1) == "<") { + line = line.substring(0, cursor.column) + "/" + line.substring(cursor.column); + var lines = session.doc.getAllLines(); + lines[cursor.row] = line; + // call mode helper to close the tag if possible + parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); + } + } + return false; + }); + + this.add("autoclosing", "insertion", function (state, action, editor, session, text) { + if (text == '>') { + var position = editor.getCursorPosition(); + var iterator = new TokenIterator(session, position.row, position.column); + var token = iterator.getCurrentToken(); + var atCursor = false; + if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))){ + do { + token = iterator.stepBackward(); + } while (token && (hasType(token, 'string') || hasType(token, 'keyword.operator') || hasType(token, 'entity.attribute-name') || hasType(token, 'text'))); + } else { + atCursor = true; + } + if (!token || !hasType(token, 'meta.tag-name') || iterator.stepBackward().value.match('/')) { + return + } + var tag = token.value; + if (atCursor){ + var tag = tag.substring(0, position.column - token.start); + } + + return { + text: '>' + '', + selection: [1, 1] + } + } + }); + } + oop.inherits(XMLBehaviour, Behaviour); + + exports.XMLBehaviour = XMLBehaviour; + }); + + define("eXide/mode/xml", function(require, exports, module) { + + var oop = require("ace/lib/oop"); + var XmlMode = require("ace/mode/xml").Mode; + var Tokenizer = require("ace/tokenizer").Tokenizer; + var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules; + var XmlFoldMode = require("ace/mode/folding/xml").FoldMode; + var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; + var Range = require("ace/range").Range; + + var Mode = function(parent) { + this.$tokenizer = new Tokenizer(new XmlHighlightRules().getRules()); + this.$behaviour = new XMLBehaviour(parent); + this.foldingRules = new XmlFoldMode(); }; - }).call(Mode.prototype); - - exports.Mode = Mode; -}); + + oop.inherits(Mode, XmlMode); + + (function() { + + this.toggleCommentLines = function(state, doc, startRow, endRow) { + var i, line; + var outdent = true; + var re = /^\s*/; + + for (i=startRow; i<= endRow; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + var range = new Range(0, 0, 0, 0); + for (i=startRow; i<= endRow; i++) { + line = doc.getLine(i); + range.start.row = i; + range.end.row = i; + range.end.column = line.length; + + doc.replace(range, outdent ? line.match(re)[1] : ""); + } + }; + + }).call(Mode.prototype); + + exports.Mode = Mode; + }); + + define("eXide/mode/html", function(require, exports, module) { + + var oop = require("ace/lib/oop"); + var HtmlMode = require("ace/mode/html").Mode; + var Tokenizer = require("ace/tokenizer").Tokenizer; + var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules; + var HtmlFoldMode = require("ace/mode/folding/html").FoldMode; + var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; + var Range = require("ace/range").Range; + var JavaScriptMode = require("ace/mode/javascript").Mode; + var CssMode = require("ace/mode/css").Mode; + + var Mode = function(parent) { + var highlighter = new HtmlHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$behaviour = new XMLBehaviour(parent); + //this.$behaviour = new HtmlBehaviour(); + this.foldingRules = new HtmlFoldMode(); + this.$embeds = highlighter.getEmbeds(); + this.createModeDelegates({ + "js-": JavaScriptMode, + "css-": CssMode + }); + }; + + oop.inherits(Mode, HtmlMode); + + (function() { + + this.toggleCommentLines = function(state, doc, startRow, endRow) { + var i, line; + var outdent = true; + var re = /^\s*/; + + for (i=startRow; i<= endRow; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + var range = new Range(0, 0, 0, 0); + for (i=startRow; i<= endRow; i++) { + line = doc.getLine(i); + range.start.row = i; + range.end.row = i; + range.end.column = line.length; + + doc.replace(range, outdent ? line.match(re)[1] : ""); + } + }; + }).call(Mode.prototype); + + exports.Mode = Mode; + }); + \ No newline at end of file From 642d3c6d73932eda6169edf7443d4aa7b5dbfe31 Mon Sep 17 00:00:00 2001 From: marmoure Date: Tue, 31 May 2022 11:18:32 +0200 Subject: [PATCH 02/10] prevent cursor jump --- src/ace-modes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ace-modes.js b/src/ace-modes.js index 1b4f58cf..9fa2a539 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -226,7 +226,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { if (text == "\"") { return { text: "\"", - selection: [] + selection: [1,1] } } return false; @@ -236,7 +236,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { if (text == "(") { return { text: "(", - selection: [] + selection: [1,1] } } return false; @@ -246,7 +246,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { if (text == "{") { return { text: "{", - selection: [] + selection: [1,1] } } return false; From f6c1d9084a598a2f6cb2ee75c9853f4d455fcfac Mon Sep 17 00:00:00 2001 From: marmoure Date: Thu, 9 Jun 2022 21:57:50 +0200 Subject: [PATCH 03/10] enable conditional autopair for quoats and paren --- index.html.tmpl | 4 ++ src/ace-modes.js | 152 ++++++++++++++++++++++++++++++++++++++++------- src/eXide.js | 5 ++ src/editor.js | 5 ++ 4 files changed, 144 insertions(+), 22 deletions(-) diff --git a/index.html.tmpl b/index.html.tmpl index 2a8388b9..906bebdc 100755 --- a/index.html.tmpl +++ b/index.html.tmpl @@ -158,6 +158,10 @@ Preferences +
  • + + autoPair +
  • diff --git a/src/ace-modes.js b/src/ace-modes.js index 9fa2a539..eaaff8fb 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -148,6 +148,43 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { var oop = require("ace/lib/oop"); var Behaviour = require('ace/mode/behaviour').Behaviour; var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; + + var context; + var contextCache = {}; + var defaultQuotes = {'"' : '"', "'" : "'"}; + + var initContext = function(editor) { + var id = -1; + if (editor.multiSelect) { + id = editor.selection.index; + if (contextCache.rangeCount != editor.multiSelect.rangeCount) + contextCache = {rangeCount: editor.multiSelect.rangeCount}; + } + if (contextCache[id]) + return context = contextCache[id]; + context = contextCache[id] = { + autoInsertedBrackets: 0, + autoInsertedRow: -1, + autoInsertedLineEnd: "", + maybeInsertedBrackets: 0, + maybeInsertedRow: -1, + maybeInsertedLineStart: "", + maybeInsertedLineEnd: "" + }; + }; + + var getWrapped = function(selection, selected, opening, closing) { + var rowDiff = selection.end.row - selection.start.row; + return { + text: opening + selected + closing, + selection: [ + 0, + selection.start.column + 1, + rowDiff, + selection.end.column + (rowDiff ? 0 : 1) + ] + }; + }; var XQueryBehaviour = function (parent) { @@ -222,34 +259,105 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { return false; }); - this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == "\"") { - return { - text: "\"", - selection: [1,1] + this.add("string_dquotes", "insertion", function(state, action, editor, session, text) { + var quotes = defaultQuotes; + var disablePair = eXide.app.getEditor().getActiveDocument().disableAutoPair + if (text.length == 1 && quotes[text]) { + if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1) + return; + initContext(editor); + var quote = text; + var selection = editor.getSelectionRange(); + var selected = session.doc.getTextRange(selection); + if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) { + return getWrapped(selection, selected, quote, quote); + } else if (!selected) { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var leftChar = line.substring(cursor.column-1, cursor.column); + var rightChar = line.substring(cursor.column, cursor.column + 1); + + var token = session.getTokenAt(cursor.row, cursor.column); + var rightToken = session.getTokenAt(cursor.row, cursor.column + 1); + // We're escaped. + if (leftChar == "\\" && token && /escape/.test(token.type)) + return null; + + var stringBefore = token && /string|escape/.test(token.type); + var stringAfter = !rightToken || /string|escape/.test(rightToken.type); + + var pair; + if (rightChar == quote) { + pair = stringBefore !== stringAfter; + if (pair && /string\.end/.test(rightToken.type)) + pair = false; + } else { + if (stringBefore && !stringAfter) + return null; // wrap string with different quote + if (stringBefore && stringAfter) + return null; // do not pair quotes inside strings + var wordRe = session.$mode.tokenRe; + wordRe.lastIndex = 0; + var isWordBefore = wordRe.test(leftChar); + wordRe.lastIndex = 0; + var isWordAfter = wordRe.test(leftChar); + if (isWordBefore || isWordAfter) + return null; // before or after alphanumeric + if (rightChar && !/[\s;,.})\]\\]/.test(rightChar)) + return null; // there is rightChar and it isn't closing + var charBefore = line[cursor.column - 2]; + if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore))) + return null; + pair = true; + } + if(!disablePair) { + return { + text: pair ? quote + quote : "", + selection: [1,1] + }; + }else return null } } - return false; }); - - this.add("parens", "insertion", function (state, action, editor, session, text) { - if (text == "(") { - return { - text: "(", - selection: [1,1] + + this.add("parens", "insertion", function(state, action, editor, session, text) { + if (text == '(') { + initContext(editor); + var disablePair = eXide.app.getEditor().getActiveDocument().disableAutoPair + var selection = editor.getSelectionRange(); + var selected = session.doc.getTextRange(selection); + if (selected !== "" && editor.getWrapBehavioursEnabled()) { + return getWrapped(selection, selected, '(', ')'); + } else if (CstyleBehaviour.isSaneInsertion(editor, session)) { + if(!disablePair) { + CstyleBehaviour.recordAutoInsert(editor, session, ")"); + return { + text: '()', + selection: [1, 1] + }; + }else { + return { + text: '(', + selection: [1, 1] + }; + } } - } - return false; - }); - - this.add("braces", "insertion", function (state, action, editor, session, text) { - if (text == "{") { - return { - text: "{", - selection: [1,1] + } else if (text == ')') { + initContext(editor); + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChar = line.substring(cursor.column, cursor.column + 1); + if (rightChar == ')') { + var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row}); + if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { + CstyleBehaviour.popAutoInsertedClosing(); + return { + text: '', + selection: [1, 1] + }; + } } } - return false; }); } diff --git a/src/eXide.js b/src/eXide.js index 8f8a2e06..ca151d43 100644 --- a/src/eXide.js +++ b/src/eXide.js @@ -1393,6 +1393,11 @@ eXide.app = (function(util) { menu.click("#menu-edit-preferences", function() { preferences.show(); }); + menu.click("#menu-toggle-autoPair", function() { + let autoPairDisabled = eXide.app.getEditor().getActiveDocument().disableAutoPair + eXide.app.getEditor().getActiveDocument().setDisableAutoPair(!autoPairDisabled) + document.getElementById("menu-toggle-autoPair").innerHTML = autoPairDisabled ? `autoPair` : `autoPair` ; + }); menu.click("#menu-navigate-definition", function () { editor.exec("gotoDefinition"); }); diff --git a/src/editor.js b/src/editor.js index 4125e6e9..ee1b50b8 100644 --- a/src/editor.js +++ b/src/editor.js @@ -38,6 +38,7 @@ eXide.edit.Document = (function() { this.lastChangeEvent = new Date().getTime(); this.lastValidation = 0; this.ast = null; + this.disableAutoPair = false var wrap = eXide.app.getPreference("softWrap"); this.$session.setUseWrapMode(wrap != 0); if (wrap > 0) { @@ -141,6 +142,10 @@ eXide.edit.Document = (function() { return this.externalLink; }; + Constr.prototype.setDisableAutoPair = function(disableAutoPair) { + this.disableAutoPair = disableAutoPair; + }; + return Constr; }()); From 51dbe21851912cfe8108788ec60897359cc95fca Mon Sep 17 00:00:00 2001 From: marmoure Date: Fri, 10 Jun 2022 12:15:54 +0200 Subject: [PATCH 04/10] minimal solution to make autopair optional --- src/ace-modes.js | 120 +++++++---------------------------------------- 1 file changed, 17 insertions(+), 103 deletions(-) diff --git a/src/ace-modes.js b/src/ace-modes.js index eaaff8fb..a23eabab 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -148,7 +148,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { var oop = require("ace/lib/oop"); var Behaviour = require('ace/mode/behaviour').Behaviour; var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; - + var context; var contextCache = {}; var defaultQuotes = {'"' : '"', "'" : "'"}; @@ -188,9 +188,6 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { var XQueryBehaviour = function (parent) { - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour - this.parent = parent; - this.add("brackets", "insertion", function (state, action, editor, session, text) { if (text == "\n") { var cursor = editor.getCursorPosition(); @@ -231,13 +228,18 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { text: '\n' + " : ", selection: [1, 3, 1, 3] } + }else if (line.match(/^\s:/) && line.match(/^\s:/) && cursor.column < line.length) { + return { + text: "\n : ", + selection: [1, 3, 1, 3] + }; } } if (text == ":") { if (line.slice(cursor.column -1 ,cursor.column) === '(') { return { text: ": :", - selection: [2, 2] + selection: [] } } } @@ -259,108 +261,21 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { return false; }); - this.add("string_dquotes", "insertion", function(state, action, editor, session, text) { - var quotes = defaultQuotes; + this.add("autoPairDisabled", "insertion", function(state, action, editor, session, text) { var disablePair = eXide.app.getEditor().getActiveDocument().disableAutoPair - if (text.length == 1 && quotes[text]) { - if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1) - return; - initContext(editor); - var quote = text; - var selection = editor.getSelectionRange(); - var selected = session.doc.getTextRange(selection); - if (selected !== "" && (selected.length != 1 || !quotes[selected]) && editor.getWrapBehavioursEnabled()) { - return getWrapped(selection, selected, quote, quote); - } else if (!selected) { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var leftChar = line.substring(cursor.column-1, cursor.column); - var rightChar = line.substring(cursor.column, cursor.column + 1); - - var token = session.getTokenAt(cursor.row, cursor.column); - var rightToken = session.getTokenAt(cursor.row, cursor.column + 1); - // We're escaped. - if (leftChar == "\\" && token && /escape/.test(token.type)) - return null; - - var stringBefore = token && /string|escape/.test(token.type); - var stringAfter = !rightToken || /string|escape/.test(rightToken.type); - - var pair; - if (rightChar == quote) { - pair = stringBefore !== stringAfter; - if (pair && /string\.end/.test(rightToken.type)) - pair = false; - } else { - if (stringBefore && !stringAfter) - return null; // wrap string with different quote - if (stringBefore && stringAfter) - return null; // do not pair quotes inside strings - var wordRe = session.$mode.tokenRe; - wordRe.lastIndex = 0; - var isWordBefore = wordRe.test(leftChar); - wordRe.lastIndex = 0; - var isWordAfter = wordRe.test(leftChar); - if (isWordBefore || isWordAfter) - return null; // before or after alphanumeric - if (rightChar && !/[\s;,.})\]\\]/.test(rightChar)) - return null; // there is rightChar and it isn't closing - var charBefore = line[cursor.column - 2]; - if (leftChar == quote && (charBefore == quote || wordRe.test(charBefore))) - return null; - pair = true; - } - if(!disablePair) { - return { - text: pair ? quote + quote : "", - selection: [1,1] - }; - }else return null - } + if(!disablePair) return null; + if (['(',"\"","'","{"].includes(text)) { + return { + text, + selection: [1, 1] + }; } }); - this.add("parens", "insertion", function(state, action, editor, session, text) { - if (text == '(') { - initContext(editor); - var disablePair = eXide.app.getEditor().getActiveDocument().disableAutoPair - var selection = editor.getSelectionRange(); - var selected = session.doc.getTextRange(selection); - if (selected !== "" && editor.getWrapBehavioursEnabled()) { - return getWrapped(selection, selected, '(', ')'); - } else if (CstyleBehaviour.isSaneInsertion(editor, session)) { - if(!disablePair) { - CstyleBehaviour.recordAutoInsert(editor, session, ")"); - return { - text: '()', - selection: [1, 1] - }; - }else { - return { - text: '(', - selection: [1, 1] - }; - } - } - } else if (text == ')') { - initContext(editor); - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == ')') { - var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row}); - if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { - CstyleBehaviour.popAutoInsertedClosing(); - return { - text: '', - selection: [1, 1] - }; - } - } - } - }); - + this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour + this.parent = parent; } + oop.inherits(XQueryBehaviour, Behaviour); exports.XQueryBehaviour = XQueryBehaviour; @@ -529,7 +444,6 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { } var XMLBehaviour = function (parent) { - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour this.parent = parent; From 983a36283c08b64338309470a3b3e31a1a454099 Mon Sep 17 00:00:00 2001 From: marmoure Date: Thu, 23 Jun 2022 17:52:51 +0200 Subject: [PATCH 05/10] move autoPair command to edit prefrences --- index.html.tmpl | 8 ++++---- src/ace-modes.js | 6 +++--- src/eXide.js | 5 ----- src/editor.js | 5 ----- src/preferences.js | 3 +++ 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/index.html.tmpl b/index.html.tmpl index 906bebdc..4c60027a 100755 --- a/index.html.tmpl +++ b/index.html.tmpl @@ -158,10 +158,6 @@ Preferences
  • -
  • - - autoPair -
  • @@ -684,6 +680,10 @@
  • +
  • + + +
  • diff --git a/src/ace-modes.js b/src/ace-modes.js index a23eabab..8d40c0b4 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -261,9 +261,9 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { return false; }); - this.add("autoPairDisabled", "insertion", function(state, action, editor, session, text) { - var disablePair = eXide.app.getEditor().getActiveDocument().disableAutoPair - if(!disablePair) return null; + this.add("autoPair", "insertion", function(state, action, editor, session, text) { + var autoPair = eXide.app.getPreference("autoPair") + if(autoPair) return null; if (['(',"\"","'","{"].includes(text)) { return { text, diff --git a/src/eXide.js b/src/eXide.js index ca151d43..8f8a2e06 100644 --- a/src/eXide.js +++ b/src/eXide.js @@ -1393,11 +1393,6 @@ eXide.app = (function(util) { menu.click("#menu-edit-preferences", function() { preferences.show(); }); - menu.click("#menu-toggle-autoPair", function() { - let autoPairDisabled = eXide.app.getEditor().getActiveDocument().disableAutoPair - eXide.app.getEditor().getActiveDocument().setDisableAutoPair(!autoPairDisabled) - document.getElementById("menu-toggle-autoPair").innerHTML = autoPairDisabled ? `autoPair` : `autoPair` ; - }); menu.click("#menu-navigate-definition", function () { editor.exec("gotoDefinition"); }); diff --git a/src/editor.js b/src/editor.js index ee1b50b8..4125e6e9 100644 --- a/src/editor.js +++ b/src/editor.js @@ -38,7 +38,6 @@ eXide.edit.Document = (function() { this.lastChangeEvent = new Date().getTime(); this.lastValidation = 0; this.ast = null; - this.disableAutoPair = false var wrap = eXide.app.getPreference("softWrap"); this.$session.setUseWrapMode(wrap != 0); if (wrap > 0) { @@ -142,10 +141,6 @@ eXide.edit.Document = (function() { return this.externalLink; }; - Constr.prototype.setDisableAutoPair = function(disableAutoPair) { - this.disableAutoPair = disableAutoPair; - }; - return Constr; }()); diff --git a/src/preferences.js b/src/preferences.js index 06b7c143..b5818c96 100644 --- a/src/preferences.js +++ b/src/preferences.js @@ -29,6 +29,7 @@ eXide.util.Preferences = (function () { fontSize: 14, font: "Default", showInvisibles: false, + autoPair: true, showPrintMargin: true, showHScroll: false, indent: -1, @@ -93,6 +94,7 @@ eXide.util.Preferences = (function () { $("input[name=\"omit-xml-decl-on-download\"]", form).attr("checked", this.preferences.omitXMLDeclarationOnDownload); $("input[name=\"omit-xml-decl-on-download-package\"]", form).attr("checked", this.preferences.omitXMLDeclarationOnDownloadPackage); $("input[name=\"show-invisibles\"]", form).attr("checked", this.preferences.showInvisibles); + $("input[name=\"auto-pair\"]", form).attr("checked", this.preferences.autoPair); $("input[name=\"print-margin\"]", form).attr("checked", this.preferences.showPrintMargin); $("input[name=\"emmet\"]", form).attr("checked", this.preferences.emmet); @@ -121,6 +123,7 @@ eXide.util.Preferences = (function () { this.preferences.fontSize = parseInt($("select[name=\"font-size\"]", form).val()); this.preferences.font = $("select[name=\"font\"]", form).val(); this.preferences.showInvisibles = $("input[name=\"show-invisibles\"]", form).is(":checked"); + this.preferences.autoPair = $("input[name=\"auto-pair\"]", form).is(":checked"); this.preferences.showPrintMargin = $("input[name=\"print-margin\"]", form).is(":checked"); this.preferences.emmet = $("input[name=\"emmet\"]", form).is(":checked"); this.preferences.indentOnOpen = $("input[name=\"indent-on-open\"]", form).is(":checked"); From 0fe4ca08112eb964b995138d043e6251c81a221c Mon Sep 17 00:00:00 2001 From: marmoure Date: Fri, 24 Jun 2022 10:38:21 +0200 Subject: [PATCH 06/10] label change --- index.html.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html.tmpl b/index.html.tmpl index 4c60027a..d9e85fe9 100755 --- a/index.html.tmpl +++ b/index.html.tmpl @@ -682,7 +682,7 @@
  • - +
  • From ea3a8eb443f322e2fd9372f07867f19cbff1e08b Mon Sep 17 00:00:00 2001 From: marmoure Date: Mon, 27 Jun 2022 11:59:16 +0200 Subject: [PATCH 07/10] resolve conficlt --- src/ace-modes.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ace-modes.js b/src/ace-modes.js index 8d40c0b4..757b734c 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -148,7 +148,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { var oop = require("ace/lib/oop"); var Behaviour = require('ace/mode/behaviour').Behaviour; var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; - + var context; var contextCache = {}; var defaultQuotes = {'"' : '"', "'" : "'"}; @@ -228,7 +228,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { text: '\n' + " : ", selection: [1, 3, 1, 3] } - }else if (line.match(/^\s:/) && line.match(/^\s:/) && cursor.column < line.length) { + }else if (line.match(/^\s:/) && line.match(/.*:\)/) && cursor.column < line.length) { return { text: "\n : ", selection: [1, 3, 1, 3] @@ -239,7 +239,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { if (line.slice(cursor.column -1 ,cursor.column) === '(') { return { text: ": :", - selection: [] + selection: [2, 2] } } } @@ -260,7 +260,7 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { } return false; }); - + this.add("autoPair", "insertion", function(state, action, editor, session, text) { var autoPair = eXide.app.getPreference("autoPair") if(autoPair) return null; @@ -271,11 +271,11 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { }; } }); - + this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour this.parent = parent; } - + oop.inherits(XQueryBehaviour, Behaviour); exports.XQueryBehaviour = XQueryBehaviour; @@ -616,5 +616,4 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { }).call(Mode.prototype); exports.Mode = Mode; - }); - \ No newline at end of file + }); \ No newline at end of file From 6133b78aa7349785355127552a65abd9e8660479 Mon Sep 17 00:00:00 2001 From: marmoure Date: Mon, 27 Jun 2022 12:02:17 +0200 Subject: [PATCH 08/10] format ace-modes --- src/ace-modes.js | 852 +++++++++++++++++++++++------------------------ 1 file changed, 426 insertions(+), 426 deletions(-) diff --git a/src/ace-modes.js b/src/ace-modes.js index 757b734c..8dff84be 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -16,58 +16,58 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { +define("eXide/mode/xquery_highlight_rules", function (require, exports, module) { var oop = require("ace/lib/oop"); var lang = require("ace/lib/lang"); var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules; - - var XQueryHighlightRules = function() { - + + var XQueryHighlightRules = function () { + var keywords = lang.arrayToMap( ("return|for|let|where|order|by|declare|function|variable|xquery|version|option|namespace|import|module|" + - "switch|default|map|" + - "if|then|else|as|and|or|typeswitch|case|ascending|descending|empty|in").split("|") + "switch|default|map|" + + "if|then|else|as|and|or|typeswitch|case|ascending|descending|empty|in").split("|") ); - + // regexp must not have capturing parentheses // regexps are ordered -> the first match is used - + this.$rules = { - start : [ { - token : "text", - regex : "<\\!\\[CDATA\\[", - next : "cdata" + start: [{ + token: "text", + regex: "<\\!\\[CDATA\\[", + next: "cdata" }, { - token : "xml_pe", - regex : "<\\?.*?\\?>" + token: "xml_pe", + regex: "<\\?.*?\\?>" }, { - token : "comment", - regex : "<\\!--", - next : "comment" + token: "comment", + regex: "<\\!--", + next: "comment" }, { - token : "comment", - regex : "\\(:", - next : "comment" + token: "comment", + regex: "\\(:", + next: "comment" }, { - token : "text", // opening tag - regex : "<\\/?", - next : "tag" + token: "text", // opening tag + regex: "<\\/?", + next: "tag" }, { - token : "constant", // number - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + token: "constant", // number + regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" }, { - token : "variable", // variable - regex : "\\$[a-zA-Z_][a-zA-Z0-9_\\-:]*\\b" + token: "variable", // variable + regex: "\\$[a-zA-Z_][a-zA-Z0-9_\\-:]*\\b" }, { token: "string", - regex : '".*?"' + regex: '".*?"' }, { token: "string", - regex : "'.*?'" + regex: "'.*?'" }, { - token : "text", - regex : "\\s+" + token: "text", + regex: "\\s+" }, { token: "comment", regex: "\\%\\w[\\w+_\\-:]+\\b" @@ -84,286 +84,286 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { token: "rparen", regex: "[\\])}]" }, { - token : function(value) { + token: function (value) { if (keywords[value]) return "keyword"; else return "identifier"; }, - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - } ], - - tag : [ { - token : "text", - regex : ">", - next : "start" + regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }], + + tag: [{ + token: "text", + regex: ">", + next: "start" }, { - token : "keyword", - regex : "[-_a-zA-Z0-9:]+" + token: "keyword", + regex: "[-_a-zA-Z0-9:]+" }, { - token : "text", - regex : "\\s+" + token: "text", + regex: "\\s+" }, { - token : "string", - regex : '".*?"' + token: "string", + regex: '".*?"' }, { - token : "string", - regex : "'.*?'" - } ], - - cdata : [ { - token : "text", - regex : "\\]\\]>", - next : "start" + token: "string", + regex: "'.*?'" + }], + + cdata: [{ + token: "text", + regex: "\\]\\]>", + next: "start" }, { - token : "text", - regex : "\\s+" + token: "text", + regex: "\\s+" }, { - token : "text", - regex : "(?:[^\\]]|\\](?!\\]>))+" - } ], - - comment : [ { - token : "comment", - regex : ".*?-->", - next : "start" + token: "text", + regex: "(?:[^\\]]|\\](?!\\]>))+" + }], + + comment: [{ + token: "comment", + regex: ".*?-->", + next: "start" }, { token: "comment", - regex : ".*:\\)", - next : "start" + regex: ".*:\\)", + next: "start" }, { - token : "comment", - regex : ".+" - } ] + token: "comment", + regex: ".+" + }] }; }; - + oop.inherits(XQueryHighlightRules, TextHighlightRules); - + exports.XQueryHighlightRules = XQueryHighlightRules; - }); - - define("eXide/mode/behaviour/xquery", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var Behaviour = require('ace/mode/behaviour').Behaviour; - var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; +}); - var context; - var contextCache = {}; - var defaultQuotes = {'"' : '"', "'" : "'"}; - - var initContext = function(editor) { - var id = -1; - if (editor.multiSelect) { - id = editor.selection.index; - if (contextCache.rangeCount != editor.multiSelect.rangeCount) - contextCache = {rangeCount: editor.multiSelect.rangeCount}; - } - if (contextCache[id]) - return context = contextCache[id]; - context = contextCache[id] = { - autoInsertedBrackets: 0, - autoInsertedRow: -1, - autoInsertedLineEnd: "", - maybeInsertedBrackets: 0, - maybeInsertedRow: -1, - maybeInsertedLineStart: "", - maybeInsertedLineEnd: "" - }; +define("eXide/mode/behaviour/xquery", function (require, exports, module) { + + var oop = require("ace/lib/oop"); + var Behaviour = require('ace/mode/behaviour').Behaviour; + var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; + + var context; + var contextCache = {}; + var defaultQuotes = { '"': '"', "'": "'" }; + + var initContext = function (editor) { + var id = -1; + if (editor.multiSelect) { + id = editor.selection.index; + if (contextCache.rangeCount != editor.multiSelect.rangeCount) + contextCache = { rangeCount: editor.multiSelect.rangeCount }; + } + if (contextCache[id]) + return context = contextCache[id]; + context = contextCache[id] = { + autoInsertedBrackets: 0, + autoInsertedRow: -1, + autoInsertedLineEnd: "", + maybeInsertedBrackets: 0, + maybeInsertedRow: -1, + maybeInsertedLineStart: "", + maybeInsertedLineEnd: "" }; - - var getWrapped = function(selection, selected, opening, closing) { - var rowDiff = selection.end.row - selection.start.row; - return { - text: opening + selected + closing, - selection: [ - 0, - selection.start.column + 1, - rowDiff, - selection.end.column + (rowDiff ? 0 : 1) - ] - }; + }; + + var getWrapped = function (selection, selected, opening, closing) { + var rowDiff = selection.end.row - selection.start.row; + return { + text: opening + selected + closing, + selection: [ + 0, + selection.start.column + 1, + rowDiff, + selection.end.column + (rowDiff ? 0 : 1) + ] }; - - var XQueryBehaviour = function (parent) { - - this.add("brackets", "insertion", function (state, action, editor, session, text) { - if (text == "\n") { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChars = line.substring(cursor.column, cursor.column + 2); - // check if pressed enter between two tags and increase indent automatically - if (rightChars == ' 0 && line.charAt(cursor.column - 1) == "<") { - line = line.substring(0, cursor.column) + '/' + line.substring(cursor.column + 1, line.length); - var lines = session.doc.getAllLines(); - lines[cursor.row] = line; - // call mode helper to close the tag if possible - parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); + } else if (line.match(/^\(:/) && !line.match(/.*:\)/)) { + return { + text: '\n' + " : ", + selection: [1, 3, 1, 3] } - } - return false; - }); - - this.add("autoPair", "insertion", function(state, action, editor, session, text) { - var autoPair = eXide.app.getPreference("autoPair") - if(autoPair) return null; - if (['(',"\"","'","{"].includes(text)) { + + } else if (line.match(/^\s:/) && (nextLine.match(/.*:\)/) || nextLine.match(/^\s:/))) { return { - text, - selection: [1, 1] + text: '\n' + " : ", + selection: [1, 3, 1, 3] + } + } else if (line.match(/^\s:/) && line.match(/.*:\)/) && cursor.column < line.length) { + return { + text: "\n : ", + selection: [1, 3, 1, 3] }; } - }); + } + if (text == ":") { + if (line.slice(cursor.column - 1, cursor.column) === '(') { + return { + text: ": :", + selection: [2, 2] + } + } + } + }); - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour - this.parent = parent; - } + // Check for open tag if user enters / and auto-close it. + this.add("slash", "insertion", function (state, action, editor, session, text) { + if (text == "/") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + if (cursor.column > 0 && line.charAt(cursor.column - 1) == "<") { + line = line.substring(0, cursor.column) + '/' + line.substring(cursor.column + 1, line.length); + var lines = session.doc.getAllLines(); + lines[cursor.row] = line; + // call mode helper to close the tag if possible + parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); + } + } + return false; + }); + + this.add("autoPair", "insertion", function (state, action, editor, session, text) { + var autoPair = eXide.app.getPreference("autoPair") + if (autoPair) return null; + if (['(', "\"", "'", "{"].includes(text)) { + return { + text, + selection: [1, 1] + }; + } + }); + + this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour + this.parent = parent; + } + + oop.inherits(XQueryBehaviour, Behaviour); + + exports.XQueryBehaviour = XQueryBehaviour; +}); + +define("eXide/mode/xquery", function (require, exports, module) { - oop.inherits(XQueryBehaviour, Behaviour); - - exports.XQueryBehaviour = XQueryBehaviour; - }); - - define("eXide/mode/xquery", function(require, exports, module) { - var oop = require("ace/lib/oop"); var TextMode = require("ace/mode/text").Mode; var XQueryLexer = require("lib/XQueryLexer").XQueryLexer; - + var Tokenizer = require("ace/tokenizer").Tokenizer; var XQueryBehaviour = require("eXide/mode/behaviour/xquery").XQueryBehaviour; var CStyleFoldMode = require("ace/mode/folding/cstyle").FoldMode; var Range = require("ace/range").Range; - - var Mode = function(parent) { + + var Mode = function (parent) { this.$tokenizer = new XQueryLexer(); this.$behaviour = new XQueryBehaviour(parent); this.foldingRules = new CStyleFoldMode(); }; - + oop.inherits(Mode, TextMode); - - (function() { - - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/); - if (match) - indent += tab; + + (function () { + + this.getNextLineIndent = function (state, line, tab) { + var indent = this.$getIndent(line); + var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/); + if (match) + indent += tab; return indent; }; - - this.checkOutdent = function(state, line, input) { - if (! /^\s+$/.test(line)) + + this.checkOutdent = function (state, line, input) { + if (! /^\s+$/.test(line)) return false; - + return /^\s*[\}\)]/.test(input); }; - - this.autoOutdent = function(state, doc, row) { - var line = doc.getLine(row); + + this.autoOutdent = function (state, doc, row) { + var line = doc.getLine(row); var match = line.match(/^(\s*[\}\)])/); - + if (!match) return 0; - + var column = match[1].length; - var openBracePos = doc.findMatchingBracket({row: row, column: column}); - + var openBracePos = doc.findMatchingBracket({ row: row, column: column }); + if (!openBracePos || openBracePos.row == row) return 0; - + var indent = this.$getIndent(doc.getLine(openBracePos.row)); - doc.replace(new Range(row, 0, row, column-1), indent); + doc.replace(new Range(row, 0, row, column - 1), indent); }; - - this.$getIndent = function(line) { + + this.$getIndent = function (line) { var match = line.match(/^(\s+)/); if (match) { return match[1]; } - + return ""; }; - - this.toggleCommentLines = function(state, doc, startRow, endRow) { + + this.toggleCommentLines = function (state, doc, startRow, endRow) { var i, line; var outdent = true; var re = /^\s*\(:(.*):\)/; - - for (i=startRow; i<= endRow; i++) { + + for (i = startRow; i <= endRow; i++) { if (!re.test(doc.getLine(i))) { outdent = false; break; } } - + var range = new Range(0, 0, 0, 0); - for (i=startRow; i<= endRow; i++) { + for (i = startRow; i <= endRow; i++) { line = doc.getLine(i); - range.start.row = i; - range.end.row = i; + range.start.row = i; + range.end.row = i; range.end.column = line.length; - + doc.replace(range, outdent ? line.match(re)[1] : "(:" + line + ":)"); } }; - + /*this.createWorker = function(session) { this.$deltas = []; var worker = new WorkerClient(["ace"], "ace/mode/xquery_worker", "XQueryWorker"); @@ -417,203 +417,203 @@ define("eXide/mode/xquery_highlight_rules", function(require, exports, module) { return worker; };*/ - + }).call(Mode.prototype); - + exports.Mode = Mode; - }); - - define("eXide/mode/behaviour/xml", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var Behaviour = require('ace/mode/behaviour').Behaviour; - var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; - var TokenIterator = require("ace/token_iterator").TokenIterator; - - function hasType(token, type) { - var hasType = true; - var typeList = token.type.split('.'); - var needleList = type.split('.'); - needleList.forEach(function(needle){ - if (typeList.indexOf(needle) == -1) { - hasType = false; - return false; - } - }); - return hasType; - } - - var XMLBehaviour = function (parent) { - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour - this.parent = parent; - - this.add("brackets", "insertion", function (state, action, editor, session, text) { - if (text == "\n") { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChars = line.substring(cursor.column, cursor.column + 2); - if (rightChars == ' 0 && line.charAt(cursor.column - 1) == "<") { - line = line.substring(0, cursor.column) + "/" + line.substring(cursor.column); - var lines = session.doc.getAllLines(); - lines[cursor.row] = line; - // call mode helper to close the tag if possible - parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); - } - } +}); + +define("eXide/mode/behaviour/xml", function (require, exports, module) { + + var oop = require("ace/lib/oop"); + var Behaviour = require('ace/mode/behaviour').Behaviour; + var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; + var TokenIterator = require("ace/token_iterator").TokenIterator; + + function hasType(token, type) { + var hasType = true; + var typeList = token.type.split('.'); + var needleList = type.split('.'); + needleList.forEach(function (needle) { + if (typeList.indexOf(needle) == -1) { + hasType = false; return false; - }); - - this.add("autoclosing", "insertion", function (state, action, editor, session, text) { - if (text == '>') { - var position = editor.getCursorPosition(); - var iterator = new TokenIterator(session, position.row, position.column); - var token = iterator.getCurrentToken(); - var atCursor = false; - if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))){ - do { - token = iterator.stepBackward(); - } while (token && (hasType(token, 'string') || hasType(token, 'keyword.operator') || hasType(token, 'entity.attribute-name') || hasType(token, 'text'))); - } else { - atCursor = true; - } - if (!token || !hasType(token, 'meta.tag-name') || iterator.stepBackward().value.match('/')) { - return - } - var tag = token.value; - if (atCursor){ - var tag = tag.substring(0, position.column - token.start); - } - + } + }); + return hasType; + } + + var XMLBehaviour = function (parent) { + this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour + this.parent = parent; + + this.add("brackets", "insertion", function (state, action, editor, session, text) { + if (text == "\n") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChars = line.substring(cursor.column, cursor.column + 2); + if (rightChars == '' + '', - selection: [1, 1] + text: '\n' + indent + '\n' + next_indent, + selection: [1, indent.length, 1, indent.length] } } - }); - } - oop.inherits(XMLBehaviour, Behaviour); - - exports.XMLBehaviour = XMLBehaviour; - }); - - define("eXide/mode/xml", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var XmlMode = require("ace/mode/xml").Mode; - var Tokenizer = require("ace/tokenizer").Tokenizer; - var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules; - var XmlFoldMode = require("ace/mode/folding/xml").FoldMode; - var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; - var Range = require("ace/range").Range; - - var Mode = function(parent) { - this.$tokenizer = new Tokenizer(new XmlHighlightRules().getRules()); - this.$behaviour = new XMLBehaviour(parent); - this.foldingRules = new XmlFoldMode(); - }; - - oop.inherits(Mode, XmlMode); - - (function() { - - this.toggleCommentLines = function(state, doc, startRow, endRow) { - var i, line; - var outdent = true; - var re = /^\s*/; - - for (i=startRow; i<= endRow; i++) { - if (!re.test(doc.getLine(i))) { - outdent = false; - break; - } + } + return false; + }); + + // Check for open tag if user enters / and auto-close it. + this.add("slash", "insertion", function (state, action, editor, session, text) { + if (text == "/") { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + if (cursor.column > 0 && line.charAt(cursor.column - 1) == "<") { + line = line.substring(0, cursor.column) + "/" + line.substring(cursor.column); + var lines = session.doc.getAllLines(); + lines[cursor.row] = line; + // call mode helper to close the tag if possible + parent.exec("closeTag", lines.join(session.doc.getNewLineCharacter()), cursor.row); } - - var range = new Range(0, 0, 0, 0); - for (i=startRow; i<= endRow; i++) { - line = doc.getLine(i); - range.start.row = i; - range.end.row = i; - range.end.column = line.length; - - doc.replace(range, outdent ? line.match(re)[1] : ""); + } + return false; + }); + + this.add("autoclosing", "insertion", function (state, action, editor, session, text) { + if (text == '>') { + var position = editor.getCursorPosition(); + var iterator = new TokenIterator(session, position.row, position.column); + var token = iterator.getCurrentToken(); + var atCursor = false; + if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))) { + do { + token = iterator.stepBackward(); + } while (token && (hasType(token, 'string') || hasType(token, 'keyword.operator') || hasType(token, 'entity.attribute-name') || hasType(token, 'text'))); + } else { + atCursor = true; } - }; - - }).call(Mode.prototype); - - exports.Mode = Mode; - }); - - define("eXide/mode/html", function(require, exports, module) { - - var oop = require("ace/lib/oop"); - var HtmlMode = require("ace/mode/html").Mode; - var Tokenizer = require("ace/tokenizer").Tokenizer; - var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules; - var HtmlFoldMode = require("ace/mode/folding/html").FoldMode; - var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; - var Range = require("ace/range").Range; - var JavaScriptMode = require("ace/mode/javascript").Mode; - var CssMode = require("ace/mode/css").Mode; - - var Mode = function(parent) { - var highlighter = new HtmlHighlightRules(); - this.$tokenizer = new Tokenizer(highlighter.getRules()); - this.$behaviour = new XMLBehaviour(parent); - //this.$behaviour = new HtmlBehaviour(); - this.foldingRules = new HtmlFoldMode(); - this.$embeds = highlighter.getEmbeds(); - this.createModeDelegates({ - "js-": JavaScriptMode, - "css-": CssMode - }); - }; - - oop.inherits(Mode, HtmlMode); - - (function() { - - this.toggleCommentLines = function(state, doc, startRow, endRow) { - var i, line; - var outdent = true; - var re = /^\s*/; - - for (i=startRow; i<= endRow; i++) { - if (!re.test(doc.getLine(i))) { - outdent = false; - break; - } + if (!token || !hasType(token, 'meta.tag-name') || iterator.stepBackward().value.match('/')) { + return } - - var range = new Range(0, 0, 0, 0); - for (i=startRow; i<= endRow; i++) { - line = doc.getLine(i); - range.start.row = i; - range.end.row = i; - range.end.column = line.length; - - doc.replace(range, outdent ? line.match(re)[1] : ""); + var tag = token.value; + if (atCursor) { + var tag = tag.substring(0, position.column - token.start); } - }; - }).call(Mode.prototype); - - exports.Mode = Mode; - }); \ No newline at end of file + + return { + text: '>' + '', + selection: [1, 1] + } + } + }); + } + oop.inherits(XMLBehaviour, Behaviour); + + exports.XMLBehaviour = XMLBehaviour; +}); + +define("eXide/mode/xml", function (require, exports, module) { + + var oop = require("ace/lib/oop"); + var XmlMode = require("ace/mode/xml").Mode; + var Tokenizer = require("ace/tokenizer").Tokenizer; + var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules; + var XmlFoldMode = require("ace/mode/folding/xml").FoldMode; + var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; + var Range = require("ace/range").Range; + + var Mode = function (parent) { + this.$tokenizer = new Tokenizer(new XmlHighlightRules().getRules()); + this.$behaviour = new XMLBehaviour(parent); + this.foldingRules = new XmlFoldMode(); + }; + + oop.inherits(Mode, XmlMode); + + (function () { + + this.toggleCommentLines = function (state, doc, startRow, endRow) { + var i, line; + var outdent = true; + var re = /^\s*/; + + for (i = startRow; i <= endRow; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + var range = new Range(0, 0, 0, 0); + for (i = startRow; i <= endRow; i++) { + line = doc.getLine(i); + range.start.row = i; + range.end.row = i; + range.end.column = line.length; + + doc.replace(range, outdent ? line.match(re)[1] : ""); + } + }; + + }).call(Mode.prototype); + + exports.Mode = Mode; +}); + +define("eXide/mode/html", function (require, exports, module) { + + var oop = require("ace/lib/oop"); + var HtmlMode = require("ace/mode/html").Mode; + var Tokenizer = require("ace/tokenizer").Tokenizer; + var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules; + var HtmlFoldMode = require("ace/mode/folding/html").FoldMode; + var XMLBehaviour = require("eXide/mode/behaviour/xml").XMLBehaviour; + var Range = require("ace/range").Range; + var JavaScriptMode = require("ace/mode/javascript").Mode; + var CssMode = require("ace/mode/css").Mode; + + var Mode = function (parent) { + var highlighter = new HtmlHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$behaviour = new XMLBehaviour(parent); + //this.$behaviour = new HtmlBehaviour(); + this.foldingRules = new HtmlFoldMode(); + this.$embeds = highlighter.getEmbeds(); + this.createModeDelegates({ + "js-": JavaScriptMode, + "css-": CssMode + }); + }; + + oop.inherits(Mode, HtmlMode); + + (function () { + + this.toggleCommentLines = function (state, doc, startRow, endRow) { + var i, line; + var outdent = true; + var re = /^\s*/; + + for (i = startRow; i <= endRow; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + var range = new Range(0, 0, 0, 0); + for (i = startRow; i <= endRow; i++) { + line = doc.getLine(i); + range.start.row = i; + range.end.row = i; + range.end.column = line.length; + + doc.replace(range, outdent ? line.match(re)[1] : ""); + } + }; + }).call(Mode.prototype); + + exports.Mode = Mode; +}); \ No newline at end of file From ebbd7961b62f92b78fd3188f33590afc06fe7df0 Mon Sep 17 00:00:00 2001 From: marmoure Date: Tue, 28 Jun 2022 17:21:38 +0200 Subject: [PATCH 09/10] edit braces & brackets pair behaviour --- src/ace-modes.js | 54 ++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/src/ace-modes.js b/src/ace-modes.js index 8dff84be..6bc5921c 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -149,43 +149,6 @@ define("eXide/mode/behaviour/xquery", function (require, exports, module) { var Behaviour = require('ace/mode/behaviour').Behaviour; var CstyleBehaviour = require('ace/mode/behaviour/cstyle').CstyleBehaviour; - var context; - var contextCache = {}; - var defaultQuotes = { '"': '"', "'": "'" }; - - var initContext = function (editor) { - var id = -1; - if (editor.multiSelect) { - id = editor.selection.index; - if (contextCache.rangeCount != editor.multiSelect.rangeCount) - contextCache = { rangeCount: editor.multiSelect.rangeCount }; - } - if (contextCache[id]) - return context = contextCache[id]; - context = contextCache[id] = { - autoInsertedBrackets: 0, - autoInsertedRow: -1, - autoInsertedLineEnd: "", - maybeInsertedBrackets: 0, - maybeInsertedRow: -1, - maybeInsertedLineStart: "", - maybeInsertedLineEnd: "" - }; - }; - - var getWrapped = function (selection, selected, opening, closing) { - var rowDiff = selection.end.row - selection.start.row; - return { - text: opening + selected + closing, - selection: [ - 0, - selection.start.column + 1, - rowDiff, - selection.end.column + (rowDiff ? 0 : 1) - ] - }; - }; - var XQueryBehaviour = function (parent) { this.add("brackets", "insertion", function (state, action, editor, session, text) { @@ -272,7 +235,22 @@ define("eXide/mode/behaviour/xquery", function (require, exports, module) { } }); - this.inherit(CstyleBehaviour, ["braces", "parens", "string_dquotes"]); // Get string behaviour + this.add("braces&brackets", "insertion", function (state, action, editor, session, text) { + var autoPair = eXide.app.getPreference("autoPair") + if (!autoPair) return null; + let pair = { + "[":"[]", + "{":"{}", + } + if (['[', "{"].includes(text)) { + return { + text: pair[text], + selection: [1, 1] + }; + } + }); + + this.inherit(CstyleBehaviour, ["parens", "string_dquotes"]); // Get string behaviour this.parent = parent; } From c6273a9495595756ac3327310c0933b95d32bcaa Mon Sep 17 00:00:00 2001 From: marmoure Date: Fri, 1 Jul 2022 18:33:41 +0200 Subject: [PATCH 10/10] braces&brackets deletion --- src/ace-modes.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ace-modes.js b/src/ace-modes.js index 6bc5921c..9c9ff2a6 100644 --- a/src/ace-modes.js +++ b/src/ace-modes.js @@ -250,6 +250,17 @@ define("eXide/mode/behaviour/xquery", function (require, exports, module) { } }); + this.add("braces&brackets", "deletion", function (state, action, editor, session, range) { + var cursor = editor.getCursorPosition(); + var line = session.doc.getLine(cursor.row); + var rightChar = line.substring(cursor.column, cursor.column + 1); + + if (['[', "{"].includes(rightChar)) { + range.end.column++ + return range; + } + }); + this.inherit(CstyleBehaviour, ["parens", "string_dquotes"]); // Get string behaviour this.parent = parent; }