diff --git a/kitty/boss.py b/kitty/boss.py index 1d1ea92..5a6a589 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -3171,10 +3171,15 @@ class Boss: self.ring_bell_if_allowed() return previews = [(text, self._clipboard_history_preview(text) or _('(blank)')) for text in entries] + # The picker is itself the active window while it is open, so keep the window the user was + # working in to paste into once it closes. The window can be gone by then. + target = self.window_for_dispatch or self.active_window def chosen(text: str | None) -> None: - if text: - self.paste_to_active_window(text) + if text and target is not None: + w = self.window_id_map.get(target.id) + if w is not None: + w.paste_with_actions(text) self.choose_entry(_('Clipboard history'), previews, chosen)