Skip to content

input: Fix prevent single-line input panic on multiline text (#2552) - #2586

Merged
huacnlee merged 9 commits into
longbridge:mainfrom
chulingera2025:fix/2552-single-line-input-newline-panic
Jul 27, 2026
Merged

input: Fix prevent single-line input panic on multiline text (#2552)#2586
huacnlee merged 9 commits into
longbridge:mainfrom
chulingera2025:fix/2552-single-line-input-newline-panic

Conversation

@chulingera2025

@chulingera2025 chulingera2025 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2552.

Activating find (cmd-f) while a selection spans multiple lines panicked the app with:

text argument should not contain newlines

The multiline selection was pushed into the single-line search input via set_value, and painting a single line whose text contains \n panics in gpui's text shaper (text_system.rs).

Changes

  • Central fix in InputState::normalize_input: for single-line inputs, collapse newlines to spaces (matching browser search/text inputs) — \r\n/\n/\r become a single space. This covers every edit path (set_value, insert, paste, IME), so multiline text stays usable instead of crashing the input.
  • Removed the now-redundant manual \n strip in paste (the central normalization handles it, including \r).
  • Search populated from a multiline selection becomes a single-line, space-joined query.
  • Added tests:
    • test_single_line_collapses_newlines_to_spacesset_value/insert with mixed \n, \r\n, \r all collapse to spaces.
    • test_search_with_multiline_selection — regression test for the original panic; asserts the single-line search input never holds a newline.

Verification

Full input test suite passes (90 tests) and clippy is clean.

Activating find (cmd-f) while a selection spans multiple lines pushed the
multiline selection into the single-line search input via `set_value`,
which later panicked in the single-line text shaper with
"text argument should not contain newlines".

Strip newlines centrally in `InputState::normalize_input` for single-line
inputs, so every edit path (set_value, insert, paste, IME) is protected
rather than just paste. The manual `\n` strip in `paste` is now redundant
and removed (normalization also handles `\r`).

Additionally, when opening search from a multiline selection, use only the
first line of the selection as the query instead of the whole block.

Adds a regression test reproducing the original panic.

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That not a good solution.

We need support multiple paste. For example in Chrome if we have multiline text, the search input will replace \n to space.

@chulingera2025

Copy link
Copy Markdown
Contributor Author

That not a good solution.

We need support multiple paste. For example in Chrome if we have multiline text, the search input will replace \n to space.

I get it now, I'll fix it.

Per review feedback: instead of dropping newlines from single-line inputs,
collapse them to spaces (matching browser search/text inputs), so pasting
or setting multiline text keeps word boundaries and stays usable.

- `normalize_input` now replaces `\r\n`/`\n`/`\r` with a single space for
  single-line inputs (was: stripped entirely).
- Search populated from a multiline selection becomes a single-line,
  space-joined query instead of just the first line.
- Add a focused unit test for set_value/insert newline collapsing, and
  update the search regression test expectation.
@chulingera2025
chulingera2025 requested a review from huacnlee July 22, 2026 08:02
@chulingera2025

Copy link
Copy Markdown
Contributor Author

The real machine test passed, the function is normal
@huacnlee

@huacnlee huacnlee changed the title fix(input): prevent single-line input panic on multiline text (#2552) input: Fix prevent single-line input panic on multiline text (#2552) Jul 27, 2026
huacnlee and others added 4 commits July 27, 2026 14:25
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
@huacnlee
huacnlee enabled auto-merge (squash) July 27, 2026 06:50
@huacnlee
huacnlee merged commit 99ac437 into longbridge:main Jul 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor component panics when search is initiated while multiple lines is selected

2 participants