From 44debfd9b94eb57a226deb54b20fca44c25f60ff Mon Sep 17 00:00:00 2001 From: Pragadesh-45 <54320162+Pragadesh-45@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:06:07 +0530 Subject: [PATCH] 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 --- .../bruno-app/src/utils/common/codemirror.js | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/bruno-app/src/utils/common/codemirror.js b/packages/bruno-app/src/utils/common/codemirror.js index 53cbcf9a0..82b98a325 100644 --- a/packages/bruno-app/src/utils/common/codemirror.js +++ b/packages/bruno-app/src/utils/common/codemirror.js @@ -52,17 +52,33 @@ 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 - for (let i = 0; i < content.length; i++) { - if (content[i] !== '\n') { - const maskedNode = document.createTextNode(this.maskChar); + + if (content.length <= 500) { + for (let i = 0; i < content.length; i++) { + if (content[i] !== '\n') { + const maskedNode = document.createTextNode(this.maskChar); + this.editor.markText( + { line: this.editor.posFromIndex(i).line, ch: this.editor.posFromIndex(i).ch }, + { line: this.editor.posFromIndex(i + 1).line, ch: this.editor.posFromIndex(i + 1).ch }, + { replacedWith: maskedNode, handleMouseEvents: true } + ); + } + } + } 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: this.editor.posFromIndex(i).line, ch: this.editor.posFromIndex(i).ch }, - { line: this.editor.posFromIndex(i + 1).line, ch: this.editor.posFromIndex(i + 1).ch }, - { replacedWith: maskedNode, handleMouseEvents: true } + { line, ch: 0 }, + { line, ch: lineLength }, + { replacedWith: maskedNode, handleMouseEvents: false } ); } }