From dfa9c097e27f08f31347ab44044632dfb5b7a9e2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 28 Sep 2026 10:40:15 +0530 Subject: [PATCH] Cleanup previous PR ensuring stale saved restore tabis not present --- kitty/boss.py | 4 ++++ kitty_tests/tab_drop.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/kitty/boss.py b/kitty/boss.py index 1b2227d2e..4f4a1d9bd 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1553,6 +1553,10 @@ class Boss: tm.handle_tab_bar_mouse(x, y, button, modifiers, action) def start_tab_drag(self, os_window_id: int, window_id: int, pixels: bytes, width: int, height: int) -> None: + # A previous drag whose drop never reached _reset_drop_previews (failed transfer, dragged + # tab closed, etc.) can leave stale pre-hover focus behind, discard it. + for q in self.all_tab_managers: + q.finish_tab_drag_hover(restore_focus=False) if tm := self.os_window_map.get(os_window_id): tm.start_tab_drag(pixels, width, height) diff --git a/kitty_tests/tab_drop.py b/kitty_tests/tab_drop.py index cde85896c..e8db7259e 100644 --- a/kitty_tests/tab_drop.py +++ b/kitty_tests/tab_drop.py @@ -144,6 +144,18 @@ class TestTabDropClassification(BossDropTest): self.tm.on_tab_drop.assert_called_once_with(600, 10) self.tm.finish_tab_drag_hover.assert_called_with(restore_focus=True) + def test_new_tab_drag_discards_stale_hover_focus(self): + # A failed drop never reaches _reset_drop_previews, so the saved focus must not survive + # into the next drag + self.boss.show_error = Mock() + Boss.on_drop(self.boss, 1, 5, True, 600, 10) + self.boss.show_error.assert_called_once() + self.tm.finish_tab_drag_hover.assert_not_called() + self.tm.start_tab_drag = Mock() + Boss.start_tab_drag(self.boss, 1, 0, b'', 0, 0) + self.tm.finish_tab_drag_hover.assert_called_once_with(restore_focus=False) + self.tm.start_tab_drag.assert_called_once_with(b'', 0, 0) + def test_cross_window_tab_bar_drop_keeps_destination_focus(self): self.source.os_window_id = 9 self.ae(self.drop(600, 10), 'tab_drop')