From 90ea252c821dfc97f2cb802a2e401bc074960422 Mon Sep 17 00:00:00 2001 From: Miao Date: Tue, 30 Sep 2025 03:25:45 +0800 Subject: [PATCH] vim: Disregard non-text content on system clipboard for yanking (#39118) Closes #39086 Release Notes: - Fixed the vim problem that image clipboard content overrides the unnamed register and produces an empty paste. --- crates/vim/src/state.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index 490f1dc7452dd37364d83b9b8321c33e9309a275..3458a92442a3ec76ebce581bf798fc57509f7d53 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -807,11 +807,10 @@ impl VimGlobals { self.last_yank.replace(content.text.clone()); cx.write_to_clipboard(content.clone().into()); } else { - self.last_yank = cx - .read_from_clipboard() - .and_then(|item| item.text().map(|string| string.into())); + if let Some(text) = cx.read_from_clipboard().and_then(|i| i.text()) { + self.last_yank.replace(text.into()); + } } - self.registers.insert('"', content.clone()); if is_yank { self.registers.insert('0', content); @@ -885,10 +884,10 @@ impl VimGlobals { fn system_clipboard_is_newer(&self, cx: &App) -> bool { cx.read_from_clipboard().is_some_and(|item| { - if let Some(last_state) = &self.last_yank { - Some(last_state.as_ref()) != item.text().as_deref() - } else { - true + match (item.text().as_deref(), &self.last_yank) { + (Some(new), Some(last)) => last.as_ref() != new, + (Some(_), None) => true, + (None, _) => false, } }) }