input: Single line code editor
Description
I want to be able to use syntax highlighting in single line inputs, I solved this by adding InputMode::SingleLineCodeEditor. But there are more ways it could be solved, for example max_rows for code_editor. But this is more complex because of all the areas we need to check for max_rows and compare it to rows. So I'm not sure how and if this is something you want to add?
I haven't added any docs or anything yet because of this.
Screenshot
I have two use cases for this,
- In my API client, I have a tree sitter language for the URL input,
- In my SQL editor I want to be able to allow JSON syntax highlighting for inline editing of json columns,
Break Changes
None
How to Test
Add .single_line_code_editor("json") for example
Checklist
- [x] I have read the CONTRIBUTING document and followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
- [x] Passed
cargo runfor story tests related to the changes. - [ ] Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)
Could also allow set_highlighter for InputMode::SingleLine
We need example for next time test.
And about the API, I think we may need to consider to change to like this:
InputState::new()
.code_editor() // default multi_line: true
.multi_line(false)
InputState::new() // Default is plain text, single line.
.multi_line(true)
enum InputMode {
Plain {
multi_line: bool,
},
CodeEditor {
multi_line: bool,
},
AutoGrow
}
And about the API, I think we may need to consider to change to like this:
InputState::new() .code_editor() // default multi_line: true .multi_line(false) InputState::new() // Default is plain text, single line. .multi_line(true) enum InputMode { Plain { multi_line: bool, }, CodeEditor { multi_line: bool, }, AutoGrow }
Good idea! I will try to do it like this
I'd like to introduce this feature, but we need improve the API design.
Updated! This is a much nicer API. Let me know if you want it backwards compatible with .multi_line()
Notable crash, but this is may not be caused by your changes.
➜ gpui-component git:(single-line-code-editor) RUST_BACKTRACE=1 cargo run -- input
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.67s
Running `target/debug/gpui-component-story input`
2025-11-28T09:56:22.128324Z INFO gpui_component_story::themes: Load themes...
2025-11-28T09:56:22.250714Z INFO gpui_component::theme::registry: Themes reloaded successfully.
2025-11-28T09:56:22.250796Z INFO gpui_component::theme::registry: Reload active theme: "macOS Classic Light"...
thread 'main' panicked at /Users/jason/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gpui-0.2.2/src/platform/mac/text_system.rs:448:57:
byte index 2 is out of bounds of `}`
stack backtrace:
0: __rustc::rust_begin_unwind
Notable crash, but this is may not be caused by your changes.
➜ gpui-component git:(single-line-code-editor) RUST_BACKTRACE=1 cargo run -- input Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.67s Running `target/debug/gpui-component-story input` 2025-11-28T09:56:22.128324Z INFO gpui_component_story::themes: Load themes... 2025-11-28T09:56:22.250714Z INFO gpui_component::theme::registry: Themes reloaded successfully. 2025-11-28T09:56:22.250796Z INFO gpui_component::theme::registry: Reload active theme: "macOS Classic Light"... thread 'main' panicked at /Users/jason/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gpui-0.2.2/src/platform/mac/text_system.rs:448:57: byte index 2 is out of bounds of `}` stack backtrace: 0: __rustc::rust_begin_unwind
Is it reproducible? I don't get any crashes on Linux, but I will try it on my Mac
Never mind, I have fixed that. You can read my commit to learn of this detail.
Never mind, I have fixed that. You can read my commit to learn of this detail.
Ah, I was just trying it on my Mac and you already fixed it :smile: Thanks!
I have also updated docs, and enabled auto-merge.
Thank you for PR.
I have also updated docs, and enabled auto-merge.
Thank you for PR.
Thanks for all the additional fixes! Sorry I missed some of the editor docs