Skip to content

Allow search/replace to span multiple lines#50783

Merged
nathansobo merged 5 commits intozed-industries:mainfrom
transitoryangel:fix/multi-line-search
Mar 19, 2026
Merged

Allow search/replace to span multiple lines#50783
nathansobo merged 5 commits intozed-industries:mainfrom
transitoryangel:fix/multi-line-search

Conversation

@transitoryangel
Copy link
Copy Markdown
Contributor

Closes #49957

Also adds start_of_input context, and modifies both {start,end}_of_input to work for both single line and auto height editor modes.

Screen.Recording.2026-03-04.at.23.09.03.mov

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • Added support for multi-line search and replace input in Buffer Search and Project Search

adds start_of_input, and allows both {start,end}_of_input to work in either single or auto height editor modes
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 5, 2026
@transitoryangel
Copy link
Copy Markdown
Contributor Author

forgot to push the padding changes - here's what it looks like on multiple lines now:
image

@injust
Copy link
Copy Markdown
Contributor

injust commented Mar 5, 2026

What do keybinds look like, now that the search bars are multi-line? Does enter still submit the search like before?

#50420 was just added to the macOS default keymap to support typing newlines with ctrl-enter.

@transitoryangel
Copy link
Copy Markdown
Contributor Author

transitoryangel commented Mar 5, 2026

What do keybinds look like, now that the search bars are multi-line? Does enter still submit the search like before?

By default in this - up and down still moves between history items, enter and shift+enter moves to the next and previous result, respectively, and ctrl+enter for newlines.

@injust
Copy link
Copy Markdown
Contributor

injust commented Mar 5, 2026

up and down still moves between history items

VS Code handles this by letting the up/down arrow keys manipulate the cursor, but if the cursor is on the first line and you press up arrow (or if the cursor is on the last line and you press down arrow), then it moves to the adjacent history item. Worth considering here.

@injust
Copy link
Copy Markdown
Contributor

injust commented Mar 5, 2026

ctrl+enter for newline

Does the ctrl-enter keybind from the Editor && mode == auto_height context apply to the search bars now? If so, then the keybinds added in #50420 can be removed.

@transitoryangel
Copy link
Copy Markdown
Contributor Author

transitoryangel commented Mar 5, 2026

up and down still moves between history items

VS Code handles this by letting the up/down arrow keys manipulate the cursor, but if the cursor is on the first line and you press up arrow (or if the cursor is on the last line and you press down arrow), then it moves to the adjacent history item. Worth considering here.

right! if it wasn't clear in my response, it does this by checking explicitly whether you are at the beginning of the first line or the end of the search input - I also tried to show this in the video but since there's no key inputs shown it's all kind of a mess.

Does the ctrl-enter keybind from the Editor && mode == auto_height context apply to the search bars now? If so, then the keybinds added in #50420 can be removed.

It does. If my comment here is addressed and this PR stays, I'll modify accordingly :)

@zelenenka zelenenka added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Mar 16, 2026
@nathansobo nathansobo self-assigned this Mar 19, 2026
…arch

Stop clearing the search query when pressing down arrow past the last
history entry. Instead, preserve the current text. In project search,
save unsubmitted text as a draft before navigating history, and restore
it when reaching the end.

In multi-line search editors, let up/down arrows move the cursor
normally within the text. Only navigate history when the content is a
single line or the cursor is at the input boundary.
After setting the search editor text during history navigation, request
autoscroll so the cursor is visible even when the content exceeds the
editor's max visible height.
@nathansobo
Copy link
Copy Markdown
Contributor

Thanks for working on this, @claiwe! Multi-line search is a great addition. @gaauwe and I tested it out and pushed a couple of follow-up commits addressing some edge cases we ran into:

Fix search history navigation and arrow key behavior (17737a56e7)

  • Pressing ↓ past the last history entry was clearing the search box. This was a pre-existing issue, but we decided to fix it here since we want ↑/↓ to feel more intuitive now that the search input supports multiple lines. It now preserves the current text instead of clearing it.
  • In project search, unsubmitted query text is saved as a "draft" before navigating history with ↑, and restored when you press ↓ past the end. This way you don't lose what you were typing.
  • Moved the multi-line arrow key logic from keybinding contexts into the action handlers themselves. For single-line content, ↑/↓ always navigate history. For multi-line content, ↑ only navigates history when the cursor is at offset 0, and ↓ only when the cursor is at the end — otherwise they move the cursor normally within the text. This simplified the keybindings back to unconditional up/down mappings.

Scroll cursor into view for long history entries (2f8c913d4e)

  • When navigating to a history entry that exceeds the editor's max visible height, the cursor wasn't scrolled into view. Added request_autoscroll after setting the text in both buffer search and project search.

@nathansobo nathansobo merged commit b0e35b6 into zed-industries:main Mar 19, 2026
29 of 30 checks passed
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
Closes zed-industries#49957 

Also adds `start_of_input` context, and modifies both
`{start,end}_of_input` to work for both single line and auto height
editor modes.


https://github.com/user-attachments/assets/e30f2b20-a96c-49d5-9eb6-3c95a485d14a

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Added support for multi-line search and replace input in Buffer Search
and Project Search

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
Closes zed-industries#49957 

Also adds `start_of_input` context, and modifies both
`{start,end}_of_input` to work for both single line and auto height
editor modes.


https://github.com/user-attachments/assets/e30f2b20-a96c-49d5-9eb6-3c95a485d14a

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Added support for multi-line search and replace input in Buffer Search
and Project Search

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
Closes zed-industries#49957 

Also adds `start_of_input` context, and modifies both
`{start,end}_of_input` to work for both single line and auto height
editor modes.


https://github.com/user-attachments/assets/e30f2b20-a96c-49d5-9eb6-3c95a485d14a

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Added support for multi-line search and replace input in Buffer Search
and Project Search

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
@esthertrapadoux esthertrapadoux moved this to Shipped by the Guild in Zed Guild - The Board Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

Status: Shipped by the Guild

Development

Successfully merging this pull request may close these issues.

Seeding search queries from the editor doesn't work across multiple lines

5 participants