From 95bdce5ea7f71b94e29e82404e5fe7af8a191335 Mon Sep 17 00:00:00 2001 From: Nanne <184182+whazor@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:17:17 +0100 Subject: [PATCH 1/2] Fix: make RTL new line a valid character We create a mechanism for specifying valid control characters. In this way, we can set wished behaviors, without making RTL mode less secure. --- src/ext/rtl.js | 6 ++++++ src/layer/text.js | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ext/rtl.js b/src/ext/rtl.js index 7c8e1f60edb..fc77333fca2 100644 --- a/src/ext/rtl.js +++ b/src/ext/rtl.js @@ -26,12 +26,18 @@ require("../config").defineOptions(Editor.prototype, "editor", { this.renderer.on("afterRender", updateLineDirection); this.commands.on("exec", onCommandEmitted); this.commands.addCommands(commands); + this.renderer.$textLayer.setControlCharacterChecker( + (position, value) => { + return (position === 0 && value === this.session.$bidiHandler.RLE); + } + ) } else { this.off("change", onChange); this.off("changeSelection", onChangeSelection); this.renderer.off("afterRender", updateLineDirection); this.commands.off("exec", onCommandEmitted); this.commands.removeCommands(commands); + this.renderer.$textLayer.setControlCharacterChecker(null); clearTextLayer(this.renderer); } this.renderer.updateFull(); diff --git a/src/layer/text.js b/src/layer/text.js index 9d3264af627..025aa0f205d 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -128,6 +128,14 @@ class Text { this.$highlightIndentGuides = highlight; return highlight; } + + /** + * change control character check, this is useful for RTL mode + * @param {null|((number, string) => boolean)} check + */ + setControlCharacterChecker(check) { + this.$controlCharacterChecker = check; + } $computeTabString() { var tabSize = this.session.getTabSize(); @@ -348,6 +356,13 @@ class Text { lines.push(this.$renderLinesFragment(config, firstRow, lastRow)); } + /** + * @param {HTMLElement} parent + * @param {number} screenColumn + * @param {*} token + * @param {string} value + * @returns + */ $renderToken(parent, screenColumn, token, value) { var self = this; var re = /(\t)|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\uFEFF\uFFF9-\uFFFC\u2066\u2067\u2068\u202A\u202B\u202D\u202E\u202C\u2069]+)|(\u3000)|([\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3001-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]|[\uD800-\uDBFF][\uDC00-\uDFFF])/g; @@ -387,7 +402,8 @@ class Text { } else { valueFragment.appendChild(this.dom.createTextNode(simpleSpace, this.element)); } - } else if (controlCharacter) { + } else if (controlCharacter && (!this.$controlCharacterChecker || !this.$controlCharacterChecker(m.index, controlCharacter))) { + console.log(screenColumn, value, this.$controlCharacterChecker(screenColumn, value)); var span = this.dom.createElement("span"); span.className = "ace_invisible ace_invisible_space ace_invalid"; span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length); @@ -786,6 +802,7 @@ Text.prototype.showSpaces = false; Text.prototype.showTabs = false; Text.prototype.showEOL = false; Text.prototype.displayIndentGuides = true; +Text.prototype.$controlCharacterChecker = null; Text.prototype.$highlightIndentGuides = true; Text.prototype.$tabStrings = []; Text.prototype.destroy = {}; From 9692cceecf87c2556e611e499d27cd4dbc5e5bdd Mon Sep 17 00:00:00 2001 From: Nanne <184182+whazor@users.noreply.github.com> Date: Thu, 28 Dec 2023 10:06:37 +0100 Subject: [PATCH 2/2] Fix and cleanup --- src/ext/rtl.js | 2 +- src/layer/text.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ext/rtl.js b/src/ext/rtl.js index fc77333fca2..23255abaa1e 100644 --- a/src/ext/rtl.js +++ b/src/ext/rtl.js @@ -30,7 +30,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { (position, value) => { return (position === 0 && value === this.session.$bidiHandler.RLE); } - ) + ); } else { this.off("change", onChange); this.off("changeSelection", onChangeSelection); diff --git a/src/layer/text.js b/src/layer/text.js index 025aa0f205d..ccd301bfa05 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -403,7 +403,6 @@ class Text { valueFragment.appendChild(this.dom.createTextNode(simpleSpace, this.element)); } } else if (controlCharacter && (!this.$controlCharacterChecker || !this.$controlCharacterChecker(m.index, controlCharacter))) { - console.log(screenColumn, value, this.$controlCharacterChecker(screenColumn, value)); var span = this.dom.createElement("span"); span.className = "ace_invisible ace_invisible_space ace_invalid"; span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);