fix: improve masking logic in MaskedEditor for large content handling (fixes #2842) (#3472)

* fix: improve masking logic in MaskedEditor for large content handling

* fix: remove comment in MaskedEditor masking logic
This commit is contained in:
Pragadesh-45 2024-11-20 18:06:07 +05:30 committed by GitHub
parent 278ca8bf29
commit 44debfd9b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,10 +52,15 @@ export class MaskedEditor {
/** Replaces all rendered characters, with the provided character. */
maskContent = () => {
const content = this.editor.getValue();
const lineCount = this.editor.lineCount();
if (lineCount === 0) return;
this.editor.operation(() => {
// Clear previous masked text
this.editor.getAllMarks().forEach((mark) => mark.clear());
// Apply new masked text
if (content.length <= 500) {
for (let i = 0; i < content.length; i++) {
if (content[i] !== '\n') {
const maskedNode = document.createTextNode(this.maskChar);
@ -66,6 +71,17 @@ export class MaskedEditor {
);
}
}
} else {
for (let line = 0; line < lineCount; line++) {
const lineLength = this.editor.getLine(line).length;
const maskedNode = document.createTextNode('*'.repeat(lineLength));
this.editor.markText(
{ line, ch: 0 },
{ line, ch: lineLength },
{ replacedWith: maskedNode, handleMouseEvents: false }
);
}
}
});
};
}