From ed48f254f1fb2f037556ed4847cfcf41a586861a Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Wed, 4 Mar 2026 15:42:09 +0530 Subject: [PATCH] feat: migrate find/replace to use CodeMirror search --- src/renderer.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/renderer.js b/src/renderer.js index 4b066c0..39dfe77 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -853,13 +853,22 @@ class TabManager { const findText = document.getElementById('find-input').value; const replaceText = document.getElementById('replace-input').value; - if (!tab || !tab.editorView || !findText) return; + if (!tab || !tab.editorView || !findText || tab.findMatches.length === 0) return; - const content = this.getEditorContent(); - const newContent = content.split(findText).join(replaceText); + const view = tab.editorView; const replacedCount = tab.findMatches.length; - this.setEditorContent(this.activeTabId, newContent); + // Build all changes as a single transaction for proper undo support. + // Changes must be provided in document order; findMatches is already sorted. + const changes = tab.findMatches.map(pos => ({ + from: pos, + to: pos + findText.length, + insert: replaceText, + })); + + view.dispatch({ changes }); + + tab.content = view.state.doc.toString(); tab.isDirty = true; this.updatePreview(this.activeTabId);