Skip to content

fix: allow replace all with an empty replacement - #3048

Merged
bajrangCoder merged 2 commits into
Acode-Foundation:mainfrom
bardrop-oss:fix-replace-all-empty-replacement
Nov 13, 2026
Merged

bajrangCoder merged 2 commits into
Acode-Foundation:mainfrom
bardrop-oss:fix-replace-all-empty-replacement

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #3044

Problem

In search in files, "replace all" did nothing when the replace field was empty, so there was no way to delete every match. replaceAll() returned early with if (!search || !replace) return;, and an empty string is falsy.

Fix

Only the search query is required now. The two replace paths already handle an empty replacement:

  • worker: content.replace(search, "")
  • native (WorkspaceIndex.runSearch): replace == null ? "" : replace, then replaceAll

Tests

New tests/unit/searchReplaceAll.test.js (same vm + source slice style as searchStreamingResults.test.js):

  • empty replacement is sent to the worker (replace-files, "")
  • empty replacement is sent to the native search (replace, "")
  • empty search query still does nothing

The first two fail on main and pass with this change. npx vitest run: 862 tests, the only failures are the 4 LSP test files that import @codemirror/lsp-client from the codemirror-lsp-client submodule, which I did not check out (same on main). biome check is clean on the changed files.

I did not test this on a device.

Search in files returned early from replaceAll() when the replace field was
empty, so there was no way to delete every match. Both the worker and the
native replace already handle an empty string, so only the search query is
required now.

Fixes Acode-Foundation#3044
@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; no new actionable issues were found.

Summary

Allows “replace all” to delete matches with an empty replacement.

  • Replace All can now delete matches with an empty replacement.

The previous unnumbered finding is fixed: openFile accepts text: "" and creates an unsaved editor instead of reading the original contents.

Reviews (3) · Last reviewed commit: "fix: keep empty replacement text for fil..." · Reviewed by Greptile

Comment thread src/sidebarApps/searchInFiles/index.js Resolved
openFile ignored supplied text when it was an empty string, so a closed
file whose whole content was replaced with "" was reloaded from disk.
@bajrangCoder
bajrangCoder added this pull request to the merge queue Nov 13, 2026
Merged via the queue into Acode-Foundation:main with commit f3b31dc Nov 13, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Nov 13, 2026
@UnschooledGamer UnschooledGamer moved this from Done to 🫡 Done by Community in The Code Board - Acode Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 🫡 Done by Community

Development

Successfully merging this pull request may close these issues.

Search in files: replace-all does nothing when the replacement is empty

3 participants