Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: make RTL new line a valid character #5434

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ext/rtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 17 additions & 1 deletion src/layer/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@
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;

Check warning on line 137 in src/layer/text.js

View check run for this annotation

Codecov / codecov/patch

src/layer/text.js#L136-L137

Added lines #L136 - L137 were not covered by tests
}

$computeTabString() {
var tabSize = this.session.getTabSize();
Expand Down Expand Up @@ -348,6 +356,13 @@
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;
Expand Down Expand Up @@ -387,7 +402,7 @@
} else {
valueFragment.appendChild(this.dom.createTextNode(simpleSpace, this.element));
}
} else if (controlCharacter) {
} else if (controlCharacter && (!this.$controlCharacterChecker || !this.$controlCharacterChecker(m.index, controlCharacter))) {
var span = this.dom.createElement("span");
span.className = "ace_invisible ace_invisible_space ace_invalid";
span.textContent = lang.stringRepeat(self.SPACE_CHAR, controlCharacter.length);
Expand Down Expand Up @@ -786,6 +801,7 @@
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 = {};
Expand Down
Loading