Skip to content

Unable to replace if replacement is an empty string #439

Closed
@mvondev

Description

@mvondev

Image

I tried to do some basic find-and-replace to my text file as follow:

  1. Bring up the find-and-replace feature (Ctrl-R or Menu -> Edit -> Replace)
  2. Type the Find: field.
  3. Leave the Replace: field (so I want to nuke all occurrences).
  4. There is no way to do replacement unless the replacement field is not empty. If it is not empty, replacement can be done by pressing Enter repeatedly. If it is empty, pressing Enter simply moves to the next occurrence without replacing.
  5. Clicking [Replace All] does nothing.

Activity

Shivix

Shivix commented on Jun 8, 2025

@Shivix
Contributor

Write is explicitly checking if the text to write is empty:

if text.is_empty() {

When removing this check, replacing with an empty string seems to works fine. We could check if text is empty outside of the function in places where write is used besides find and replace. This is already done here:

edit/src/tui.rs

Line 2696 in 5c5471e

if !write.is_empty() {

That said, we could instead utilise extract_selection(true) here instead. It's more explicit and I expect it'll be more performant.

added a commit that references this issue on Jun 10, 2025
e693aa5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @mvondev@Shivix

      Issue actions

        Unable to replace if replacement is an empty string · Issue #439 · microsoft/edit