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",
"cexpr",
"clang-sys",
"itertools 0.10.5",
"itertools 0.11.0",
"lazy_static",
"lazycell",
"log",
@ -628,7 +628,7 @@ dependencies = [
"bitflags 2.9.1",
"cexpr",
"clang-sys",
"itertools 0.10.5",
"itertools 0.11.0",
"log",
"prettyplease",
"proc-macro2",
@ -1185,7 +1185,7 @@ dependencies = [
[[package]]
name = "collections"
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 = [
"indexmap 2.7.1",
"rustc-hash 2.1.0",
@ -1692,7 +1692,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
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 = [
"proc-macro2",
"quote",
@ -2710,7 +2710,7 @@ dependencies = [
[[package]]
name = "gpui"
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 = [
"anyhow",
"as-raw-xcb-connection",
@ -2834,7 +2834,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
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 = [
"proc-macro2",
"quote",
@ -3103,7 +3103,7 @@ dependencies = [
[[package]]
name = "http_client"
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 = [
"anyhow",
"bytes",
@ -3120,7 +3120,7 @@ dependencies = [
[[package]]
name = "http_client_tls"
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 = [
"rustls",
"rustls-platform-verifier",
@ -3881,7 +3881,7 @@ dependencies = [
[[package]]
name = "media"
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 = [
"anyhow",
"bindgen 0.71.1",
@ -5626,7 +5626,7 @@ dependencies = [
[[package]]
name = "refineable"
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 = [
"derive_refineable",
"workspace-hack",
@ -5721,7 +5721,7 @@ dependencies = [
[[package]]
name = "reqwest_client"
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 = [
"anyhow",
"bytes",
@ -6241,7 +6241,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]]
name = "semantic_version"
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 = [
"anyhow",
"serde",
@ -6709,7 +6709,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
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 = [
"arrayvec",
"log",
@ -7547,7 +7547,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "util"
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 = [
"anyhow",
"async-fs 2.1.2",

View file

@ -1517,14 +1517,13 @@ impl InputState {
let mut index = 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 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.
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);
@ -1536,13 +1535,14 @@ impl InputState {
// The fallback index is saved in Err from `index_for_position` method.
index += index_result.unwrap_err();
break;
} else if line.len() == 0 {
// empty line
} else if line.text.trim_end_matches(|c| c == '\r').len() == 0 {
// empty line on Windows is `\r`, other is ''
let line_bounds = Bounds {
origin: line_origin,
size: gpui::size(bounds.size.width, line_height),
};
let pos = inner_position;
index += line.len();
if line_bounds.contains(&pos) {
break;
}
@ -1550,7 +1550,7 @@ impl InputState {
index += line.len();
}
// add 1 for \n
// +1 for revert `lines` split `\n`
index += 1;
}