A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
fix(gui): land a slow paste where it was started
RoversXb2d7f545e1a0
diff --git a/wezterm-gui/src/termwindow/clipboard.rs b/wezterm-gui/src/termwindow/clipboard.rsindex f62874fe..fbe44e8d 100644--- a/wezterm-gui/src/termwindow/clipboard.rs+++ b/wezterm-gui/src/termwindow/clipboard.rs@@ -130,6 +130,8 @@ impl TermWindow {let cursor = pane.get_cursor_position();if pane.send_paste(text).is_ok() {self.light_up_terminal_paste(pane, text, cursor);+ // A slow clipboard can answer after the person has scrolled away.+ self.maybe_scroll_to_bottom_for_input(pane);}}diff --git a/wezterm-gui/src/termwindow/content_view.rs b/wezterm-gui/src/termwindow/content_view.rsindex d7a4242c..1b2a3276 100644--- a/wezterm-gui/src/termwindow/content_view.rs+++ b/wezterm-gui/src/termwindow/content_view.rs@@ -847,6 +847,13 @@ pub(crate) trait ContentView {ContentViewResponse::Redraw}+ /// Tells where a paste would land now from anywhere else it could: which+ /// form, and which field of it. A paste that comes back to a different+ /// answer is dropped.+ fn paste_target(&self) -> (usize, usize) {+ (0, 0)+ }+/// Handle the synthetic tab close button / Escape-style close request.fn on_close_requested(&mut self) -> ContentViewResponse {ContentViewResponse::Closediff --git a/wezterm-gui/src/termwindow/keyevent.rs b/wezterm-gui/src/termwindow/keyevent.rsindex bfbe5fcb..0e75083b 100644--- a/wezterm-gui/src/termwindow/keyevent.rs+++ b/wezterm-gui/src/termwindow/keyevent.rs@@ -249,8 +249,14 @@ mod content_view_key_routing_tests {}impl super::TermWindow {- fn paste_text_into_inline_tab_rename(&mut self, text: &str) {- if let Some(rename) = self.inline_tab_rename.as_mut() {+ /// Only the edit this paste was started in: a clipboard can answer after+ /// that one has ended and another begun, of the same name too.+ fn paste_text_into_inline_tab_rename(&mut self, edit: u64, text: &str) {+ if let Some(rename) = self+ .inline_tab_rename+ .as_mut()+ .filter(|rename| rename.edit == edit)+ {rename.input.caret_insert(text, false);self.update_title_impl();if let Some(window) = self.window.as_ref() {@@ -312,13 +318,14 @@ impl super::TermWindow {return true;}KeyCode::Char('v') | KeyCode::Char('V') => {- if let Some(window) = self.window.as_ref().cloned() {+ let edit = self.inline_tab_rename.as_ref().map(|rename| rename.edit);+ if let (Some(window), Some(edit)) = (self.window.as_ref().cloned(), edit) {let future = window.get_clipboard(Clipboard::Clipboard);promise::spawn::spawn(async move {if let Ok(text) = future.await {window.notify(crate::termwindow::TermWindowNotif::Apply(Box::new(move |term_window| {- term_window.paste_text_into_inline_tab_rename(&text);+ term_window.paste_text_into_inline_tab_rename(edit, &text);},)));}diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex 5ae70f1a..7933902f 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -1960,10 +1960,13 @@ struct InlineTabRename {input: TextInputState,/// The text the editor opened with.initial: String,+ /// Tells this edit from every other, of the same target too.+ edit: u64,}impl InlineTabRename {fn new(target: InlineTabRenameTarget, text: String) -> Self {+ static LAST_EDIT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);let mut input = TextInputState::new();input.set_text_end(text.clone());input.caret_select_all();@@ -1971,6 +1974,7 @@ impl InlineTabRename {target,input,initial: text,+ edit: LAST_EDIT.fetch_add(1, std::sync::atomic::Ordering::Relaxed),}}@@ -9466,12 +9470,16 @@ impl TermWindow {ClipboardPasteSource::Clipboard => ::window::Clipboard::Clipboard,ClipboardPasteSource::PrimarySelection => ::window::Clipboard::PrimarySelection,};+ let target = self.active_content_view().map(|view| view.paste_target());let future = window.get_clipboard(clipboard);promise::spawn::spawn(async move {if let Ok(clip) = future.await {window.notify(TermWindowNotif::Apply(Box::new(move |myself| {+ // Only where this paste was started: a clipboard can+ // answer after the focus has moved on.let resp = myself.content_view_mut_by_id(view_id)+ .filter(|v| Some(v.paste_target()) == target).map(|v| v.on_paste(&clip));if let Some(resp) = resp {myself.handle_content_response_for(view_id, resp);diff --git a/wezterm-gui/src/termwindow/ssh_hosts_view.rs b/wezterm-gui/src/termwindow/ssh_hosts_view.rsindex f27fec13..a1c1ac59 100644--- a/wezterm-gui/src/termwindow/ssh_hosts_view.rs+++ b/wezterm-gui/src/termwindow/ssh_hosts_view.rs@@ -477,6 +477,9 @@ pub(crate) struct SshHostsView {selected: usize,focus: Focus,form: Option<HostForm>,+ /// Bumped by every form opened or closed: another host's form has the+ /// same fields, and a paste started in one must not land in the other.+ form_generation: usize,filtered: Vec<SshHostEntry>,system_host_count: usize,system_hosts_collapsed: bool,@@ -552,6 +555,7 @@ impl SshHostsView {selected: 0,focus: Focus::Search,form: None,+ form_generation: 0,filtered: Vec::new(),system_host_count: 0,system_hosts_collapsed: true,@@ -681,6 +685,7 @@ impl SshHostsView {// choice starts on plain ssh.form.multiplexing = true;self.form = Some(form);+ self.form_generation += 1;self.focus = Focus::Field(FIELD_HOST);self.reset_form_scroll();}@@ -766,6 +771,7 @@ impl SshHostsView {.map(|(key, value)| (text_input_with(key), text_input_with(value))).collect::<Vec<_>>();let advanced_open = !options.is_empty();+ self.form_generation += 1;self.form = Some(HostForm {editing: Some(project_id.to_string()),original: Some(spec),@@ -787,6 +793,7 @@ impl SshHostsView {fn close_form(&mut self) {self.form = None;+ self.form_generation += 1;self.focus = Focus::Search;// Revealing a password is a decision about one host, not a mode.self.password_visible = false;@@ -6233,6 +6240,18 @@ impl ContentView for SshHostsView {self.on_paste_impl(text)}+ fn paste_target(&self) -> (usize, usize) {+ // Each kind of field in its own residue, its row in the rest.+ let field = match self.focus {+ Focus::Search => 0,+ Focus::Field(row) => 1 + row * 4,+ Focus::OptionKey(row) => 2 + row * 4,+ Focus::OptionValue(row) => 3 + row * 4,+ Focus::Tailnet(row) => 4 + row * 4,+ };+ (self.form_generation, field)+ }+fn begin_new_remote_host(&mut self) {// Same reset the `+` button performs; the list refreshes on paint.self.open_new_form();@@ -6313,6 +6332,19 @@ mod tests {}}+ /// Two hosts' forms have the same fields and open on the same one: a+ /// paste started in the first must not land in the second.+ #[test]+ fn another_hosts_form_is_another_place_to_paste_into() {+ use super::ContentView;+ let mut view = SshHostsView::new();+ view.open_form_for("one", spec("prod-1", "192.0.2.7"));+ let first = view.paste_target();+ assert_eq!(view.paste_target(), first);+ view.open_form_for("two", spec("prod-2", "192.0.2.8"));+ assert_ne!(view.paste_target(), first);+ }+#[test]fn the_host_list_follows_a_trackpad_and_glides_on_a_wheel() {use super::ContentView;diff --git a/wezterm-gui/src/termwindow/ui/right_sidebar.rs b/wezterm-gui/src/termwindow/ui/right_sidebar.rsindex c4af0798..f4d308af 100644--- a/wezterm-gui/src/termwindow/ui/right_sidebar.rs+++ b/wezterm-gui/src/termwindow/ui/right_sidebar.rs@@ -322,6 +322,19 @@ const FILE_PREVIEW_HEADER_HEIGHT: usize = 64;/// running transfers are never dropped, however many there are.const REMOTE_TRANSFER_STRIP_MAX: usize = 3;+#[derive(Clone, PartialEq)]+struct RightSidebarPasteTarget {+ mode: RightSidebarMode,+ keys_held: bool,+ /// The Markdown preview in the way, by its instance.+ preview: Option<u64>,+ /// Otherwise the Note's document, by its session.+ note_session: Option<usize>,+ file_focus: Option<RightSidebarFileField>,+ snippet_view: RightSidebarSnippetView,+ snippet_focus: Option<RightSidebarSnippetField>,+}+#[derive(Clone)]pub(crate) struct TerminalPasteTarget {pane_id: PaneId,@@ -6432,11 +6445,17 @@ impl crate::TermWindow {ClipboardPasteSource::Clipboard => Clipboard::Clipboard,ClipboardPasteSource::PrimarySelection => Clipboard::PrimarySelection,};+ let target = self.right_sidebar_paste_target();let future = window.get_clipboard(clipboard);promise::spawn::spawn(async move {if let Ok(text) = future.await {window.notify(TermWindowNotif::Apply(Box::new(move |term_window| {- if term_window.push_right_sidebar_text(&text) {+ // Only the surface this paste was started in: a clipboard+ // can answer after the panel has moved on, and the Note+ // saves what lands in it.+ if term_window.right_sidebar_paste_target() == target+ && term_window.push_right_sidebar_text(&text)+ {term_window.invalidate_window();}})));@@ -6445,6 +6464,37 @@ impl crate::TermWindow {.detach();}+ /// What decides where `push_right_sidebar_text` puts its text. A paste+ /// can start with the preview installed as the note surface and land+ /// with it put away again, so the preview is named by its instance rather+ /// than by which surface is installed.+ fn right_sidebar_paste_target(&self) -> RightSidebarPasteTarget {+ let preview = if self.note_surface_installed == NoteSurface::FilePreview {+ Some(self.note_surface_instance)+ } else if self.right_sidebar_markdown_preview_focused() {+ self.right_sidebar_markdown_preview+ .as_ref()+ .map(|preview| preview.instance)+ } else {+ None+ };+ let note_session = self+ .right_sidebar_note+ .session+ .as_ref()+ .filter(|_| preview.is_none())+ .map(|session| Arc::as_ptr(session) as *const () as usize);+ RightSidebarPasteTarget {+ mode: self.right_sidebar_mode,+ keys_held: self.plugin_panel_keys_held,+ preview,+ note_session,+ file_focus: self.right_sidebar_file_focus,+ snippet_view: self.right_sidebar_snippet_view.clone(),+ snippet_focus: self.right_sidebar_snippet_focus,+ }+ }+pub(crate) fn clear_right_sidebar_focused_input_selection(&mut self) {if let RightSidebarMode::Plugin(_) = self.right_sidebar_mode {return self.plugin_panel_clear_selection();