Fix input history (#179)

This commit is contained in:
Jason Lee 2024-08-27 13:52:19 +08:00 committed by GitHub
parent 1dbf809e99
commit ad5e480e63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 14 deletions

20
Cargo.lock generated
View file

@ -966,7 +966,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"rustc-hash",
]
@ -1279,7 +1279,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"proc-macro2",
"quote",
@ -2230,7 +2230,7 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"anyhow",
"as-raw-xcb-connection",
@ -2331,7 +2331,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"proc-macro2",
"quote",
@ -2535,7 +2535,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"anyhow",
"derive_more",
@ -3095,7 +3095,7 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"anyhow",
"bindgen",
@ -4214,7 +4214,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"derive_refineable",
]
@ -4549,7 +4549,7 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]]
name = "semantic_version"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"anyhow",
"serde",
@ -4998,7 +4998,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"arrayvec",
"log",
@ -5662,7 +5662,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "util"
version = "0.1.0"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#f5eecd7d1c1a4d6fe3a09efd0a08738ef1248121"
source = "git+https://github.com/huacnlee/zed.git?branch=export-platform-window#1d2c6954e827c1ab91eba6495a43441ec04602b2"
dependencies = [
"anyhow",
"async-fs 1.6.0",

View file

@ -190,14 +190,18 @@ impl TextInput {
/// Set the text of the input field.
pub fn set_text(&mut self, text: impl Into<SharedString>, cx: &mut ViewContext<Self>) {
self.history.ignore = true;
let text: SharedString = text.into();
let range = 0..self.text.chars().map(|c| c.len_utf16()).sum();
self.replace_text_in_range(Some(range), &text, cx);
self.replace_text(text, cx);
self.history.ignore = false;
cx.notify();
}
fn replace_text(&mut self, text: impl Into<SharedString>, cx: &mut ViewContext<Self>) {
let text: SharedString = text.into();
let range = 0..self.text.chars().map(|c| c.len_utf16()).sum();
self.replace_text_in_range(Some(range), &text, cx);
}
/// Set the disabled state of the input field.
pub fn set_disabled(&mut self, disabled: bool, cx: &mut ViewContext<Self>) {
self.disabled = disabled;
@ -375,7 +379,7 @@ impl TextInput {
}
fn clean(&mut self, _: &ClickEvent, cx: &mut ViewContext<Self>) {
self.set_text("", cx);
self.replace_text("", cx);
}
fn on_mouse_down(&mut self, event: &MouseDownEvent, cx: &mut ViewContext<Self>) {