WYSIWYG: Added text direction support for code editor popup

Editor popup will now reflect the direction of the opened code block.
This also updates in-editor codemirror instances to correcly reflect/use
the direction if set on the inner code elem.

This also defaults new code blocks, when in RTL languages, to be started
in LTR, which can then be changed via in-editor direction controls if
needed. This is on the assumption that most code will be LTR (could not
find much examples of RTL code use).

Fixes #4943
This commit is contained in:
Dan Brown
2024-05-03 13:35:30 +01:00
parent 4c1c315594
commit f9e087330b
4 changed files with 43 additions and 11 deletions

View File

@ -129,7 +129,7 @@ export class CodeEditor extends Component {
this.hide();
}
async open(code, language, saveCallback, cancelCallback) {
async open(code, language, direction, saveCallback, cancelCallback) {
this.languageInput.value = language;
this.saveCallback = saveCallback;
this.cancelCallback = cancelCallback;
@ -137,6 +137,7 @@ export class CodeEditor extends Component {
await this.show();
this.languageInputChange(language);
this.editor.setContent(code);
this.setDirection(direction);
}
async show() {
@ -156,6 +157,15 @@ export class CodeEditor extends Component {
});
}
setDirection(direction) {
const target = this.editorInput.parentElement;
if (direction) {
target.setAttribute('dir', direction);
} else {
target.removeAttribute('dir');
}
}
hide() {
this.getPopup().hide();
this.addHistory();