Skip to content

fix(search): update open tabs in the background on replace all - #3049

Open
bardrop wants to merge 2 commits into
Acode-Foundation:mainfrom
bardrop-oss:fix-replace-all-background-tabs
Open

bardrop wants to merge 2 commits into
Acode-Foundation:mainfrom
bardrop-oss:fix-replace-all-background-tabs

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #3043

Problem

Replace all in "Search in files" calls openFile(url, { render, text }) for each replaced file, with render: false for every file except the last. When a file was already open, openFile ignored render: it always called makeActive() on the tab and then wrote the new text into the live editor. So a replace over many open tabs switched through every one of them, which is what the video in the issue shows, and it is slow.

Fix

In the "file already open" path of openFile, when render === false, text is given, and the tab is loaded (and no pane, cursor or encoding change is asked for), the new text goes through existingFile.session.setValue() without activating the tab. That proxy already handles inactive tabs: it updates the stored state and marks the file as edited/unsaved. The last file (render: true) still opens as before. Tabs that are not loaded yet keep the old path.

Tests

Three new cases in tests/unit/openFileCancellation.test.js (the file that already loads the real openFile module):

  • background update of an open tab does not call makeActive and sets the text (fails before)
  • same text: no change, no switch (fails before)
  • render not false: still switches and dispatches as before

npx vitest run: all pass except the 4 LSP test files that need the @codemirror/lsp-client submodule (same on main). biome check clean.

This branch is separate from #3048 (empty replacement); they touch different lines and merge cleanly.

Replace all calls openFile with render: false for every file but the
last. For a file that was already open, openFile ignored render and
always made the tab active before writing the new text, so a large
replace switched through every open tab.

Now a loaded, already open tab gets its text through its session
without being activated when render is false.
@bardrop
bardrop force-pushed the fix-replace-all-background-tabs branch from d276abd to 5f647ed Compare November 12, 2026 16:03
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both previously reported failures are addressed.

Summary

Updates open tabs during replace-all without switching focus.

  • Replace-all updates open tabs without switching to each one.

Both previous findings are addressed. No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Background replacement] --> B{File shown in a pane?}
  B -->|Yes| C[Update that pane's editor]
  C --> D[Listener syncs text and schedules autosave]
  B -->|No| E[Update stored text]
  E --> F[Schedule background autosave]
  F --> G{Still open and unsaved?}
  G -->|Yes| H[Save current text]
  G -->|No| I[Skip save]
Loading

Reviews (2) · Last reviewed commit: "fix(search): keep split panes and autosa..." · Reviewed by Greptile

Comment thread src/lib/openFile.js Resolved
Comment thread src/lib/openFile.js Resolved
Edit the live view of a pane that shows the tab, so focusing it later
does not bring back the old text. Hidden tabs get autosave scheduled,
since no view listener runs for them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Search in files: replace-all switches through every already-open tab, making it much slower

1 participant