From d34af957645e0b4287122cf4dae0730be8565e80 Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Wed, 18 Nov 2026 10:55:48 +0100 Subject: [PATCH] fix(cli-rs): number a dialog field's ctrl+c clear as an edit fields-fix numbers each change of a field, and a view's echo names the number it saw. The ctrl+c clear of a dialog surface's field reported its change without one, so it no longer built. It now takes the next number and records it with the field's other edits. --- packages/cli-rs/crates/plugin/src/reconcile.rs | 11 ++++++----- packages/cli-rs/crates/plugin/src/surface.rs | 4 ++-- .../cli-rs/crates/tui/tests/all/plugin_surface.rs | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/cli-rs/crates/plugin/src/reconcile.rs b/packages/cli-rs/crates/plugin/src/reconcile.rs index 70d7655aa6e..8716fe22050 100644 --- a/packages/cli-rs/crates/plugin/src/reconcile.rs +++ b/packages/cli-rs/crates/plugin/src/reconcile.rs @@ -653,8 +653,8 @@ impl Tree { } /// Empties the tree's input that has the focus, if it shows text, as an edit of the user's would: the id of the - /// input, whose handler is to hear the change. - pub(crate) fn clear_focused_field(&self, app: &App) -> Option { + /// input and the edit's number, which its handler is to hear. + pub(crate) fn clear_focused_field(&self, app: &App) -> Option<(String, u64)> { let focused = app.focused()?.id(); let mut cleared = None; each(&self.nodes, &mut |node| { @@ -663,12 +663,13 @@ impl Tree { && !field.draft().0.is_empty() { field.set(""); + let seq = EDITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1; let mut reported = reported.borrow_mut(); if reported.len() == ECHOES { - reported.remove(0); + reported.pop_front(); } - reported.push(String::new()); - cleared = Some(id.to_owned()); + reported.push_back((seq, String::new())); + cleared = Some((id.to_owned(), seq)); } }); cleared diff --git a/packages/cli-rs/crates/plugin/src/surface.rs b/packages/cli-rs/crates/plugin/src/surface.rs index 9de56b5817a..f0a8cddf2db 100644 --- a/packages/cli-rs/crates/plugin/src/surface.rs +++ b/packages/cli-rs/crates/plugin/src/surface.rs @@ -1433,9 +1433,9 @@ impl Claimed for Rc { } fn clear_field(&self, host: &dyn Host) -> bool { - let Some(node) = self.state.borrow().tree.clear_focused_field(host.app()) else { return false }; + let Some((node, seq)) = self.state.borrow().tree.clear_focused_field(host.app()) else { return false }; if let Some(owner) = self.holder() { - owner.hear(&abi::interact::Event::Change { node, text: String::new() }); + owner.hear(&abi::interact::Event::Change { node, text: String::new(), seq }); } true } diff --git a/packages/cli-rs/crates/tui/tests/all/plugin_surface.rs b/packages/cli-rs/crates/tui/tests/all/plugin_surface.rs index 57cf10459a2..3065453ebe8 100644 --- a/packages/cli-rs/crates/tui/tests/all/plugin_surface.rs +++ b/packages/cli-rs/crates/tui/tests/all/plugin_surface.rs @@ -1695,8 +1695,8 @@ fn dialog_probe(setup: &mut abi::Setup) -> Result<(), String> { })); let record = |_: &dyn abi::Host, event: &abi::interact::Event| { let line = match event { - abi::interact::Event::Change { node, text } if node == "name" => format!("change {text}"), - abi::interact::Event::Change { node, text } => format!("change {node} {text}"), + abi::interact::Event::Change { node, text, .. } if node == "name" => format!("change {text}"), + abi::interact::Event::Change { node, text, .. } => format!("change {node} {text}"), abi::interact::Event::Closed { surface } => format!("closed {surface}"), // Big-boi's ds-7: a bind of escape that would take it. abi::interact::Event::Key(key) if key.bind.as_deref() == Some("esc") => {