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.
This commit is contained in:
Miao
2025-09-29 13:25:45 -06:00
committed by GitHub
parent 6e5ff6d091
commit 90ea252c82
+7 -8
View File
@@ -807,11 +807,10 @@ impl VimGlobals {
self.last_yank.replace(content.text.clone()); self.last_yank.replace(content.text.clone());
cx.write_to_clipboard(content.clone().into()); cx.write_to_clipboard(content.clone().into());
} else { } else {
self.last_yank = cx if let Some(text) = cx.read_from_clipboard().and_then(|i| i.text()) {
.read_from_clipboard() self.last_yank.replace(text.into());
.and_then(|item| item.text().map(|string| string.into())); }
} }
self.registers.insert('"', content.clone()); self.registers.insert('"', content.clone());
if is_yank { if is_yank {
self.registers.insert('0', content); self.registers.insert('0', content);
@@ -885,10 +884,10 @@ impl VimGlobals {
fn system_clipboard_is_newer(&self, cx: &App) -> bool { fn system_clipboard_is_newer(&self, cx: &App) -> bool {
cx.read_from_clipboard().is_some_and(|item| { cx.read_from_clipboard().is_some_and(|item| {
if let Some(last_state) = &self.last_yank { match (item.text().as_deref(), &self.last_yank) {
Some(last_state.as_ref()) != item.text().as_deref() (Some(new), Some(last)) => last.as_ref() != new,
} else { (Some(_), None) => true,
true (None, _) => false,
} }
}) })
} }