Commit graph

108 commits

Author SHA1 Message Date
Daniel Bulant
4d0dde1f23
feat(input): support custom text highlights 2026-08-19 00:48:55 +02:00
Floyd Wang
c67821ef39 chore: Locking core-text version 2026-02-05 18:50:40 +08:00
Duane Bester
3c23ee9be4 editor: Add InlineCompletion LSP support (#1736)
Closes [1729](https://github.com/longbridge/gpui-component/issues/1729)

## Description

Adds support for inline completions, which allows the editor to support
agentic "tab to complete" solutions. This works, (tested macOS), but not
sure of any gotchas or different approaches.

## Screenshot


https://github.com/user-attachments/assets/8e437f1e-9792-4417-b070-0a1dd8de6024

## How to Test

User implements the `inline_completion` method in CompletionsProvider.

Not implementing should have no effect. 

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-12-08 10:53:36 +08:00
Andreas Johansson
8fcf5f337d
input: Fix resetting highlighting for single line code editor (#1742)
## Description

When using `set_value` with a `code_editor("lang").multi_line(false)`
the highlighting and lsp will not be reset.

## Video

### Before

https://github.com/user-attachments/assets/5fef5b6e-478e-4233-a911-e087f889040a

### After

https://github.com/user-attachments/assets/3ea99060-8dba-4604-9d3f-c151b3aadcf2

## How to Test

`cargo run --release -- input`, enter some text in "Single line code
editor", click "Reset"

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)
2025-12-05 09:53:07 +08:00
Andreas Johansson
0126f1b036
input: Fix wrong font being used in Input. (#1706)
Closes #1665

## Description

When `Input::new().font_family("font")` is used, the font hasn't been
applied yet in `Input::render`, therefore the `text_wrapper` will
calculate using the wrong font. This is why it's working when the font
is added to the parent element.

The fix moves the state update to `element` prepaint, where
`window.text_style()` has the correct styles. The only downside is that
there are now one additional state update.

## Screenshot

| Before                       | After                       |
| ---------------------------- | --------------------------- |
| <img width="1125" height="246" alt="Screenshot From 2025-11-30
20-03-11"
src="https://github.com/user-attachments/assets/1fa798a7-0b9c-4386-8940-ad5f6734b8a0"
/> | <img width="1125" height="246" alt="Screenshot From 2025-11-30
20-00-23"
src="https://github.com/user-attachments/assets/e970e7bc-1bfa-4a55-a342-3381d1684526"
/> |

## How to Test

Use some wide font, like `IBM Plex Mono`. Apply it to
`Input::new(&some_state).font_family("IBM Plex Mono")` where the input
state has `soft_wrap`. Here is a diff for `textarea_story.rs`.

```diff
diff --git a/crates/story/src/textarea_story.rs b/crates/story/src/textarea_story.rs
index f2c63d44..bd5cbb31 100644
--- a/crates/story/src/textarea_story.rs
+++ b/crates/story/src/textarea_story.rs
@@ -77,9 +77,9 @@ impl TextareaStory {
 
         let textarea_no_wrap = cx.new(|cx| {
             InputState::new(window, cx)
-                .multi_line(true)
                 .rows(6)
-                .soft_wrap(false)
+                .multi_line(true)
+                .soft_wrap(true)
                 .default_value("This is a very long line of text to test if the horizontal scrolling function is working properly, and it should not wrap automatically but display a horizontal scrollbar.\nThe second line is also very long text, used to test the horizontal scrolling effect under multiple lines, and you can input more content to test.\nThe third line: Here you can input other long text content that requires horizontal scrolling.\n")
         });
 
@@ -195,7 +185,7 @@ impl Render for TextareaStory {
             .child(
                 section("Auto Grow")
                     .max_w_md()
-                    .child(Input::new(&self.textarea_auto_grow)),
+                    .child(Input::new(&self.textarea_auto_grow).font_family("IBM Plex Mono")),
             )
             .child(
                 section("Auto Grow with No Wrap")
```


## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-12-01 09:05:34 +00:00
FlyingYu
a792719dbe
editor: Fix cursor direction not resetting after mouse up (#1708)
## Description

This PR fixes an issue where the editor's "reverse cursor" state was not
reset
after completing a text selection. Because the flag remained `true`, the
cursor
could appear on the wrong side of the selection when the next
interaction
started.

## Screenshot

| Before | After |
|--------|--------|
| <video
src="https://github.com/user-attachments/assets/308c5119-52da-4bdb-9a94-36617d957c63"
controls width="360"></video> | <video
src="https://github.com/user-attachments/assets/bf9328b4-96d8-48df-9cc0-99fccaced7c5"
controls width="360"></video> |

## How to Test

`cargo run --example editor`

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [ ] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)
2025-12-01 11:06:40 +08:00
Andreas Johansson
7e479aa7f2
input: Add to support CodeEditor as single line mode. (#1696)
## Screenshot

From `input_story`:

<img width="1069" height="122" alt="Screenshot From 2025-11-28 09-14-03"
src="https://github.com/user-attachments/assets/f14ef2fc-4939-4ceb-be3e-bede492f8602"
/>

## Breaking Changes

- `.multi_line()` was changed to `.multi_line(bool)`.  
- Removed pub `InputMode`, this should only for internal.

```diff
InputState::new(window, cx)
-    .multi_line()
+    .multi_line(true)
```

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

Use cases,

1) In my API client, I have a tree sitter language for the URL input,

<img width="1001" height="162" alt="Image"
src="https://github.com/user-attachments/assets/9771decf-b0b7-4230-8ed6-784a95b72af1"
/>

2) In my SQL editor I want to be able to allow JSON syntax highlighting
for inline editing of json columns,

<img width="501" height="130" alt="Image"
src="https://github.com/user-attachments/assets/f0f879cc-841f-49d2-a23a-2effc3747f38"
/>

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-28 19:51:40 +08:00
Jason Lee
df9655e80a
input: Adjust blink cursor height. (#1704) 2025-11-28 09:54:48 +00:00
Jason Lee
4a3f520c5f
scrollbar: Manage ScrollbarState in Scrollbar internal. (#1690)
This PR to improve the Scrollbar API to manage the state in the
internal.

## Break Changes

Describe any breaking changes introduced by this pull request. If none,
remove this section.

- Removed `scrollbar_state` argument from `Scrollbar::new`,
`Scrollbar::both`, `Scrollbar::vertical` and `Scrollbar::horizontal`.

```diff
- Scrollbar::horizontal(&self.scrollbar_state, &self.scroll_handle)
+ Scrollbar::horizontal(&self.scroll_handle)

- Scrollbar::vertical(&self.scrollbar_state, &self.scroll_handle)
+ Scrollbar::vertical(&self.scroll_handle)
```

- Change `struct ScrollbarState` to private, we not need this not.

```diff
- pub struct ScrollbarState {
+ struct ScrollbarState {
```

- Renamed `trait ScrollHandleOffsetable` to `trait ScrollbarHanle`.

```diff
- pub trait ScrollHandleOffsetable {
+ pub trait ScrollbarHanle {
```

- Removed `Scrollbar::both`, now use `Scrollbar::new` instead.

```diff
- Scrollbar::both(&scroll_handle)
+ Scrollbar::new(&scroll_handle)
```
2025-11-27 11:39:58 +08:00
Jason Lee
dae5fcd8aa
editor: Improve scroll to support position at the edge of the editor on click. (#1672)
But if we use `Up`, `Down` to move the cursor, it still will keep 3
lines.

https://github.com/user-attachments/assets/4310a4cc-3829-4190-9be9-e7159c688884
2025-11-24 09:37:59 +00:00
Jason Lee
8144085077
input: Fix scroll to offset to support soft wrap mode. (#1671)
Close #1655

https://github.com/user-attachments/assets/ea7032d0-d15a-4127-9b0b-b035e2c835fe
2025-11-24 09:14:39 +00:00
chulingera2025
d4c4b9ad37
input: Avoid blocking vertical scroll events in single-line mode (#1562) (#1572)
Fixes #1562

  ## Problem
Single-line input fields were blocking all scroll wheel events,
preventing parent containers from handling vertical page scrolling.

  ## Solution
  - Check if input is in single-line mode and scroll is purely vertical
  - Allow vertical scroll events to propagate in single-line mode
  - Only stop propagation when scroll offset actually changes

  ## Behavior
  - Single-line inputs: vertical scroll passes through to parent
  - Multi-line inputs: all scroll behavior unchanged
  - Horizontal scrolling still works in both modes
2025-11-13 10:19:52 +08:00
FlyingYu
9228dbfb13
editor: Improve double-click for word selection (#1491)
Close #876 

https://github.com/user-attachments/assets/bb04b3ab-05ca-456c-bb14-b812a846701d

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-10 05:02:02 +00:00
Jason Lee
945db0be56
dialog: Rename Modal to Dialog. (#1538)
## Break Change

- Renamed `Modal` to `Dialog`.

```diff
- window.open_modal(...)
+ window.open_dialog(...)

- window.close_modal(...);
+ window.close_dialog(...);
```

- Renamed `show_close` method to `close_button` in Dialog.
```diff
- .show_close(false)
+ .close_button(true)
```
2025-11-07 17:25:55 +08:00
Jason Lee
4dc10165fb
spinner: Rename Indicator to Spinner. (#1526)
## Break Change

- Renamed `Indicator` to `Spinner`.

```diff
- use gpui_component::indicator::Indicator;
+ use gpui_component::spinner::Spinner;
```
2025-11-06 11:36:39 +08:00
Moulberry
e7aa8983dc
input: Delete selected text with modifier keys (#1497)
In most applications, when text is selected and backspace/delete is
pressed, the selection is simply deleted.

Currently, gpui-component will ignore the selected text and delete the
previous/next word when Ctrl is pressed.

This can be very confusing especially if you do ctrl+a then
ctrl+backspace, expecting the input to be cleared.

This PR makes it so that if there is an active selection, the active
selection is deleted before doing any extra processing.
2025-11-04 16:54:31 +08:00
Jason Lee
34ef0ff6d0
chore: Rename Dropdown to Select, TextInput to Input. (#1449)
## Break Change

- The `Dropdown` has been renamed to `Select`.
- The `TextInput` has been renamed to `Input`.

| Before | After |
| --- | --- |
| TextInput | Input |
| Dropdown | Select |
| DropdownItem | SelectItem |
| DropdownItemGroup | SelectGroup |
| DropdownState | SelectState |
| DropdownEvent | SelectEvent |
| DropdownDelegate | SelectDelegate |
| dropdown::ListEvent | ~~Removed~~ |

- Renamed `PopupMenuExt` to `DropdownMenu`.
- Removed pub mod `menu::popup_menu`, `menu::context_menu`, they are
moved into `menu` mod.
- Renamed `popup_menu` method to `dropdown_menu` for `DropdownMenu`,
`Panel`, `PanelView` and `DropdownButton`.

| Before | After |
| --- | --- |
| popup_menu::PopupMenuExt | menu::DropdownMenu |
| popup_menu | dropdown_menu |
| popup_menu_with_anchor | dropdown_menu_with_anchor |
2025-10-28 21:22:31 +08:00
Jason Lee
178269be63
editor: Add indent guides. (#1426)
<img width="1070" height="1006" alt="image"
src="https://github.com/user-attachments/assets/a456b055-b45f-45ae-84b0-452a952cc19c"
/>
2025-10-24 19:03:09 +08:00
Jason Lee
6dd857a7f7
input: Fix may flash scroll when move cursor in auto grow mode. (#1419) 2025-10-23 17:43:33 +08:00
Jason Lee
1af28c49bd
input: Stop propagation on scroll wheel. (#1406)
Close #1397
2025-10-21 18:50:50 +08:00
Jason Lee
1adaf3ec55
tree: Add Tree. (#1373)
Close #318 


https://github.com/user-attachments/assets/1fed12e2-df53-4213-a3f5-c57bd8b4cadb
2025-10-15 18:39:47 +08:00
Jason Lee
59f4e26c7b
input: Fix Input panics when masked have non-ASCII characters. (#1382)
Close #1377
2025-10-15 07:15:50 +00:00
Jason Lee
889382cba1
input: Grouping input history to avoid IME placeholder. (#1375) 2025-10-14 13:27:23 +00:00
Jason Lee
97df4efd46
input: Fix set_value when Input is disabled. (#1362)
Close #1350
2025-10-13 11:15:32 +08:00
Jason Lee
6817c8d3cc
menu: Add AppMenuBar. (#1338)
- input: Change Input to not unselect when blur.
- popup_menu: Fix get key binding on PopupMenu with action context.

<img width="935" height="694" alt="image"
src="https://github.com/user-attachments/assets/295fa84e-f1d8-4f6f-8a77-601a45f8ad6d"
/>

## TODO

- [x] Keyboard support. 
- [x] Add submenu to example.
- [ ] ~~Icon~~ and check support. Wait
https://github.com/zed-industries/zed/pull/39876
2025-10-10 21:03:16 +08:00
Jason Lee
6ca9ac46fa
chore: Bump crate version. (#1340) 2025-10-09 15:20:34 +08:00
Floyd Wang
66851c55e4 Bump gpui (#1336) 2025-10-08 11:20:06 +08:00
Jason Lee
d0396d779e
editor: Add document_colors LSP. (#1329) 2025-10-06 18:08:12 +08:00
Jason Lee
794f4d6397
editor: Add to support move vertical for soft wrapped lines. (#1312) 2025-10-03 18:19:37 +08:00
Jason Lee
a48232cefd
input: Clean to reset selection and scroll offset. (#1326)
- Focus back to input when click `clean` button.
2025-10-03 16:11:27 +08:00
Floyd Wang
1358b2906e
Bump gpui (#1324)
* Wireup the `Pixels` change
https://github.com/zed-industries/zed/pull/39367.
2025-10-03 14:32:29 +08:00
Jason Lee
6028de3b5a
editor: Input enter to get next indent level performance. (#1304)
Now we can handle about 1M lines.

https://github.com/user-attachments/assets/cb55cd18-6755-40cd-a5b0-3d0f865d12e1
2025-09-29 17:35:58 +08:00
Jason Lee
aca03d47c0
input: Fix Input to unselect on blur. (#1303) 2025-09-29 17:29:11 +08:00
Jason Lee
5e504d10bb
chore: Refactor tab key to switch focus. (#991)
Wait https://github.com/zed-industries/zed/pull/33008,
https://github.com/zed-industries/zed/pull/34804 to merge.


https://github.com/user-attachments/assets/3c21ebc9-44a0-4311-bb0f-5f63fe8d4bb3

- Improved `focus_ring` to render like an outline.
- Added to support press `Enter`, `Space` key to trigger Checkbox,
Button, Radio.

## Break Changes

- The `FocusableExt` has been changed to only for crate internal.
- The `FocusableCycle` has been removed, now GPUI has it own tab stop
implementation.
2025-09-29 16:48:24 +08:00
Jason Lee
172015f147
input: Use shape line for soft wrap lines. (#1293)
This change aim to fix the before version `shape_text` (in Element
paint) and `wrap_line` (in TextWrapper cached soft wrap map) may have
difference wrap width.

Now move to based on TextWrapper's wrap map to paint text by use
`shape_line` method.
2025-09-28 10:31:03 +08:00
Jason Lee
6b7a481fc8
editor: Improve TextWrapper performance. (#1292) 2025-09-25 20:02:17 +08:00
Jason Lee
ef1d727c3d
chore: Improve RopeExt API and add more docs. (#1289) 2025-09-25 18:17:46 +08:00
Jason Lee
8f5bff61fb
chore: Fix sum_tree API changes. (#1286)
https://github.com/zed-industries/zed/pull/38776
2025-09-25 10:41:37 +08:00
Jason Lee
5aaf8c6a66
input: Fix move cursor to scroll x to viewport. (#1285) 2025-09-24 21:15:13 +08:00
Jason Lee
1c3eca93b8
editor: Revert to use ropey. (#1284)
For the License reason.

- The performance is slow down, before version can handle 200K lines,
now 150K lines is good.
2025-09-24 20:52:18 +08:00
Jason Lee
bf5650b5db
input: Add context menu for cut, copy, paste. (#1279)
Close #27

<img width="756" height="674" alt="image"
src="https://github.com/user-attachments/assets/07884a7e-366b-47b8-8bd7-a88f3cae52b8"
/>
2025-09-23 22:06:58 +08:00
Jason Lee
993ce34bd8
editor: Avoid scroll on select all. (#1277)
- Add `replace_text_in_range_silent` for some case to avoid show
completion, for example on cut, paster ...
- Improve to only call validation, mask on single line mode.
- Improve move cursor to scroll to visible to keep edge 3 lines.

https://github.com/user-attachments/assets/ca8bcca8-a55b-4c98-af7c-7639d1c34923

- Fix `RopeExt::offset_to_position` may crash.
- Add deffered_scroll_offset to improve paste to scroll to cursor.

https://github.com/user-attachments/assets/1af09a50-37f0-47c8-8185-4b78820d064a
2025-09-23 15:59:48 +08:00
Jason Lee
c80704d4d8
input: Fix invalid vertical scroll in single line mode. (#1273) 2025-09-22 19:47:47 +08:00
Jason Lee
aa0f6d6222
editor: Improve range_to_utf16 and range_from_utf16 by use Rope. (#1268)
Now, we can work on 200K lines (editing).

--------

Now, all cost are on tree-sitter parse.

<img width="1091" height="672" alt="image"
src="https://github.com/user-attachments/assets/b111bc58-1334-40b2-9920-7006ad86bb3c"
/>
2025-09-22 14:07:30 +08:00
Jason Lee
692057f799
editor: Update completions to support CompletionTextEdit. (#1267)
- Fix completion menu width to longest item.
2025-09-22 11:39:50 +08:00
Jason Lee
13fa76e00d
editor: Improve TextWrapper performance by only rebuild changed lines. (#1266)
Continue #1220 

Now, we can support editing on 100K lines (release mode).



https://github.com/user-attachments/assets/2daccc85-c713-4ddf-b08d-840cb1bb2643
2025-09-20 02:35:48 +08:00
Jason Lee
299e5ed5fc
input: Fix possible IME input crash. (#1264) 2025-09-19 17:33:18 +08:00
Jason Lee
5e7a2cb37f
editor: Add DefinitionProvider. (#1261)
https://github.com/user-attachments/assets/f8234a3f-3075-48ce-ae46-8ea869b6a13d

- Hold `cmd` to hover on a word to trigger definition check.
2025-09-19 13:49:24 +08:00
Jason Lee
6a817d6a05
editor: Add to support HoverPopover. (#1260)
<img width="725" height="631" alt="image"
src="https://github.com/user-attachments/assets/0f4aba90-82cc-43c8-916b-b4a446b8abae"
/>
2025-09-18 18:18:54 +08:00
Jason Lee
a942c57627 editor: Refactor the LSP config. 2025-09-18 14:17:18 +08:00