Rework go to line infrastructure (#23654)

Closes https://github.com/zed-industries/zed/issues/12024


https://github.com/user-attachments/assets/60ea3dbd-b594-4bf5-a44d-4bff925b815f

* Fixes incorrect line selection for certain corner cases

Before:

<img width="1728" alt="image"
src="https://github.com/user-attachments/assets/35aaee6c-c120-4bf1-9355-448a29d1b9b5"
/>

After:

<img width="1728" alt="image"
src="https://github.com/user-attachments/assets/abd97339-4594-4e8e-8605-50d74581ae86"
/>


* Reworks https://github.com/zed-industries/zed/pull/16420 to display
selection length with less performance overhead.
Improves the performance more, doing a single selections loop instead of
two.

* Fixes incorrect caret position display when text contains UTF-8 chars
with size > 1
Also fixes tooltop values for this case

* Fixes go to line to treat UTF-8 chars with size > 1 properly when
navigating

* Adds a way to fill go to line text editor with its tooltip on `Tab`

Release Notes:

- Fixed incorrect UTF-8 characters handling in `GoToLine` and caret
position
This commit is contained in:
Kirill Bulatov 2025-01-25 21:24:19 +02:00 committed by GitHub
parent 7c0a39daa6
commit da2bd4b8e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 365 additions and 69 deletions

View file

@ -261,10 +261,25 @@ fn test_text_summary_for_range() {
BufferId::new(1).unwrap(),
"ab\nefg\nhklm\nnopqrs\ntuvwxyz".into(),
);
assert_eq!(
buffer.text_summary_for_range::<TextSummary, _>(0..2),
TextSummary {
len: 2,
chars: 2,
len_utf16: OffsetUtf16(2),
lines: Point::new(0, 2),
first_line_chars: 2,
last_line_chars: 2,
last_line_len_utf16: 2,
longest_row: 0,
longest_row_chars: 2,
}
);
assert_eq!(
buffer.text_summary_for_range::<TextSummary, _>(1..3),
TextSummary {
len: 2,
chars: 2,
len_utf16: OffsetUtf16(2),
lines: Point::new(1, 0),
first_line_chars: 1,
@ -278,6 +293,7 @@ fn test_text_summary_for_range() {
buffer.text_summary_for_range::<TextSummary, _>(1..12),
TextSummary {
len: 11,
chars: 11,
len_utf16: OffsetUtf16(11),
lines: Point::new(3, 0),
first_line_chars: 1,
@ -291,6 +307,7 @@ fn test_text_summary_for_range() {
buffer.text_summary_for_range::<TextSummary, _>(0..20),
TextSummary {
len: 20,
chars: 20,
len_utf16: OffsetUtf16(20),
lines: Point::new(4, 1),
first_line_chars: 2,
@ -304,6 +321,7 @@ fn test_text_summary_for_range() {
buffer.text_summary_for_range::<TextSummary, _>(0..22),
TextSummary {
len: 22,
chars: 22,
len_utf16: OffsetUtf16(22),
lines: Point::new(4, 3),
first_line_chars: 2,
@ -317,6 +335,7 @@ fn test_text_summary_for_range() {
buffer.text_summary_for_range::<TextSummary, _>(7..22),
TextSummary {
len: 15,
chars: 15,
len_utf16: OffsetUtf16(15),
lines: Point::new(2, 3),
first_line_chars: 4,