input: Fix click can not to position cursor on empty line on Windows. (#875)

Reverts longbridge/gpui-component#874

Ref https://github.com/zed-industries/zed/pull/31031
This commit is contained in:
Jason Lee 2025-05-21 10:01:53 +08:00 committed by GitHub
parent 1b13bd707a
commit 445b1e4e02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 20 deletions

28
Cargo.lock generated
View file

@ -605,7 +605,7 @@ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"itertools 0.10.5", "itertools 0.11.0",
"lazy_static", "lazy_static",
"lazycell", "lazycell",
"log", "log",
@ -628,7 +628,7 @@ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"itertools 0.10.5", "itertools 0.11.0",
"log", "log",
"prettyplease", "prettyplease",
"proc-macro2", "proc-macro2",
@ -1185,7 +1185,7 @@ dependencies = [
[[package]] [[package]]
name = "collections" name = "collections"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"indexmap 2.7.1", "indexmap 2.7.1",
"rustc-hash 2.1.0", "rustc-hash 2.1.0",
@ -1692,7 +1692,7 @@ dependencies = [
[[package]] [[package]]
name = "derive_refineable" name = "derive_refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2710,7 +2710,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui" name = "gpui"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"as-raw-xcb-connection", "as-raw-xcb-connection",
@ -2834,7 +2834,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui_macros" name = "gpui_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3103,7 +3103,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client" name = "http_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -3120,7 +3120,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client_tls" name = "http_client_tls"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"rustls", "rustls",
"rustls-platform-verifier", "rustls-platform-verifier",
@ -3881,7 +3881,7 @@ dependencies = [
[[package]] [[package]]
name = "media" name = "media"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bindgen 0.71.1", "bindgen 0.71.1",
@ -5626,7 +5626,7 @@ dependencies = [
[[package]] [[package]]
name = "refineable" name = "refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"derive_refineable", "derive_refineable",
"workspace-hack", "workspace-hack",
@ -5721,7 +5721,7 @@ dependencies = [
[[package]] [[package]]
name = "reqwest_client" name = "reqwest_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -6241,7 +6241,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]] [[package]]
name = "semantic_version" name = "semantic_version"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
@ -6709,7 +6709,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "sum_tree" name = "sum_tree"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"log", "log",
@ -7547,7 +7547,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "util" name = "util"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=webview#34a0426d9ddc5f2b119e33eb2515ffd0e1c420ce" source = "git+https://github.com/huacnlee/zed.git?branch=webview#431fa17bcca92294fa8c8b453ebdcb4069169489"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-fs 2.1.2", "async-fs 2.1.2",

View file

@ -1517,14 +1517,13 @@ impl InputState {
let mut index = 0; let mut index = 0;
let mut y_offset = px(0.); let mut y_offset = px(0.);
for line in lines.iter() { for (_, line) in lines.iter().enumerate() {
let line_origin = self.line_origin_with_y_offset(&mut y_offset, &line, line_height); let line_origin = self.line_origin_with_y_offset(&mut y_offset, &line, line_height);
let pos = inner_position - line_origin; let pos = inner_position - line_origin;
let closest_index = line.unwrapped_layout.closest_index_for_x(pos.x);
// Return offset by use closest_index_for_x if is single line mode. // Return offset by use closest_index_for_x if is single line mode.
if self.is_single_line() { if self.is_single_line() {
return closest_index; return line.unwrapped_layout.closest_index_for_x(pos.x);
} }
let index_result = line.closest_index_for_position(pos, line_height); let index_result = line.closest_index_for_position(pos, line_height);
@ -1536,13 +1535,14 @@ impl InputState {
// The fallback index is saved in Err from `index_for_position` method. // The fallback index is saved in Err from `index_for_position` method.
index += index_result.unwrap_err(); index += index_result.unwrap_err();
break; break;
} else if line.len() == 0 { } else if line.text.trim_end_matches(|c| c == '\r').len() == 0 {
// empty line // empty line on Windows is `\r`, other is ''
let line_bounds = Bounds { let line_bounds = Bounds {
origin: line_origin, origin: line_origin,
size: gpui::size(bounds.size.width, line_height), size: gpui::size(bounds.size.width, line_height),
}; };
let pos = inner_position; let pos = inner_position;
index += line.len();
if line_bounds.contains(&pos) { if line_bounds.contains(&pos) {
break; break;
} }
@ -1550,7 +1550,7 @@ impl InputState {
index += line.len(); index += line.len();
} }
// add 1 for \n // +1 for revert `lines` split `\n`
index += 1; index += 1;
} }