From ad5e480e63dd796d69e7765f687ccf9ba2e805c6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 27 Aug 2024 13:52:19 +0800 Subject: [PATCH] Fix input history (#179) --- Cargo.lock | 20 ++++++++++---------- crates/ui/src/input/input.rs | 12 ++++++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16443431..0249eaab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index d5d866b3..7e7cdbe1 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -190,14 +190,18 @@ impl TextInput { /// Set the text of the input field. pub fn set_text(&mut self, text: impl Into, cx: &mut ViewContext) { 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, cx: &mut ViewContext) { + 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.disabled = disabled; @@ -375,7 +379,7 @@ impl TextInput { } fn clean(&mut self, _: &ClickEvent, cx: &mut ViewContext) { - self.set_text("", cx); + self.replace_text("", cx); } fn on_mouse_down(&mut self, event: &MouseDownEvent, cx: &mut ViewContext) {