From 3b5e166a145661ba08bf4c4011ddf03096b13b29 Mon Sep 17 00:00:00 2001 From: Quino Terrasa <26749475+espetro@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:01:42 -0800 Subject: [PATCH 1/2] fix(little-window): close the focused panel with Command-W --- .../Fixed-20261201-195120.765461.yaml | 3 +++ Lilo/Window/MainWindowController+Input.swift | 6 +++--- .../LittleWindow/LittleWindowTests.swift | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Fixed-20261201-195120.765461.yaml diff --git a/.changes/unreleased/Fixed-20261201-195120.765461.yaml b/.changes/unreleased/Fixed-20261201-195120.765461.yaml new file mode 100644 index 000000000..86f58c1e5 --- /dev/null +++ b/.changes/unreleased/Fixed-20261201-195120.765461.yaml @@ -0,0 +1,3 @@ +kind: Fixed +body: Command-W and File > Close Tab now close the focused Little window instead of the tab in the browser window behind it +time: 2026-12-01T19:51:20.765461-08:00 diff --git a/Lilo/Window/MainWindowController+Input.swift b/Lilo/Window/MainWindowController+Input.swift index b14dafee1..aca166152 100644 --- a/Lilo/Window/MainWindowController+Input.swift +++ b/Lilo/Window/MainWindowController+Input.swift @@ -407,12 +407,12 @@ extension MainWindowController { func handleMonitoredKeyboardEvent(_ event: NSEvent) -> Bool { // Every window's monitor sees every key: a browser window handles its own, and the - // active one also those of floating panels (extension popovers, panels). Page popups, - // the detached inspector, sheets and modal panels keep their keys. + // active one also those of floating panels without commands of their own (extension popovers, + // panels). Page popups, Little windows, the detached inspector, sheets and modal panels keep theirs. let target = event.window guard target === window || (context.windows.activeWindow === self - && (target == nil || (target is NSPanel && !(target is NSSavePanel) + && (target == nil || (target is NSPanel && !(target is LittlePanel) && !(target is NSSavePanel) && target?.sheetParent == nil && NSApp.modalWindow == nil))) else { return false } if isShowingWhatsNew { return false } diff --git a/LiloTests/LittleWindow/LittleWindowTests.swift b/LiloTests/LittleWindow/LittleWindowTests.swift index 1fa5d49c8..d43c40551 100644 --- a/LiloTests/LittleWindow/LittleWindowTests.swift +++ b/LiloTests/LittleWindow/LittleWindowTests.swift @@ -49,6 +49,13 @@ final class LittleWindowTests: XCTestCase { )) } + private func commandW(in window: NSWindow) throws -> NSEvent { + try XCTUnwrap(NSEvent.keyEvent( + with: .keyDown, location: .zero, modifierFlags: [.command], timestamp: 0, windowNumber: window.windowNumber, + context: nil, characters: "w", charactersIgnoringModifiers: "w", isARepeat: false, keyCode: 13 + )) + } + func testNewLittleWindowOpensTheStartCardOutsideTheTabList() throws { let tabs = controller.tabManager.openTabs.count @@ -101,6 +108,19 @@ final class LittleWindowTests: XCTestCase { } } + func testCommandWInALittleWindowClosesItNotATabBehind() async throws { + let tab = try XCTUnwrap(controller.createTabStateFirst(url: URL(string: "https://example.com/behind"))) + let little = try openPage() + let event = try commandW(in: little.window) + + XCTAssertFalse(controller.handleMonitoredKeyboardEvent(event), "the panel keeps the key its menu answer needs") + little.closeCurrentTab(nil) + + XCTAssertFalse(little.window.isVisible) + XCTAssertTrue(controller.littleWindows.isEmpty) + XCTAssertNotNil(controller.tabManager.tab(for: tab.id), "the tab in the browser window behind stays open") + } + func testEscapeClosesAPageWindowWhileThePageHasTheKeyboard() throws { let little = try openPage() little.chromeDidLoad() From 2e554e71a48c52a492dd6cf959179c187f46c637 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 2 Dec 2026 23:28:35 +0100 Subject: [PATCH 2/2] fix(little-window): keep browser shortcuts while routing close and reload to the panel Excluding Little windows from the browser window's key monitor left Cmd-T, Cmd-1..9, Ctrl-Tab and extension commands dead there, and let a page swallow Cmd-W. The monitor sees the panel's keys again and sends the shortcuts the panel answers itself (close tab, close window, open location, reload, copy URL) to it. --- Lilo/Window/MainWindowController+Input.swift | 14 ++++++-- .../LittleWindow/LittleWindowTests.swift | 36 +++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Lilo/Window/MainWindowController+Input.swift b/Lilo/Window/MainWindowController+Input.swift index aca166152..b645a56d9 100644 --- a/Lilo/Window/MainWindowController+Input.swift +++ b/Lilo/Window/MainWindowController+Input.swift @@ -407,12 +407,12 @@ extension MainWindowController { func handleMonitoredKeyboardEvent(_ event: NSEvent) -> Bool { // Every window's monitor sees every key: a browser window handles its own, and the - // active one also those of floating panels without commands of their own (extension popovers, - // panels). Page popups, Little windows, the detached inspector, sheets and modal panels keep theirs. + // active one also those of floating panels (extension popovers, panels, Little windows). Page popups, + // the detached inspector, sheets and modal panels keep their keys. let target = event.window guard target === window || (context.windows.activeWindow === self - && (target == nil || (target is NSPanel && !(target is LittlePanel) && !(target is NSSavePanel) + && (target == nil || (target is NSPanel && !(target is NSSavePanel) && target?.sheetParent == nil && NSApp.modalWindow == nil))) else { return false } if isShowingWhatsNew { return false } @@ -482,6 +482,14 @@ extension MainWindowController { } // Without a page, as on a terminal tab, these keys go on to the focused view and the menus. if focusedEngineTab == nil, ["history.back", "history.forward", "page.print", "page.save"].contains(id) { return false } + // A Little window closes, reloads and addresses its own page; its other shortcuts act on this window. + if let little = event.window as? LittlePanel, let action = [ + "tab.close": #selector(closeCurrentTab(_:)), "window.close": #selector(NSWindow.performClose(_:)), + "location.open": #selector(openLocation(_:)), "page.reload": #selector(reloadCurrentPage(_:)), + "page.copyURL": #selector(copyCurrentURL(_:)) + ][id] { + return little.tryToPerform(action, with: nil) + } switch id { case "tab.new": // A blank tab keeps its existing toggle behavior; a page stays visible under the new-tab bar. diff --git a/LiloTests/LittleWindow/LittleWindowTests.swift b/LiloTests/LittleWindow/LittleWindowTests.swift index d43c40551..157fe7735 100644 --- a/LiloTests/LittleWindow/LittleWindowTests.swift +++ b/LiloTests/LittleWindow/LittleWindowTests.swift @@ -49,10 +49,10 @@ final class LittleWindowTests: XCTestCase { )) } - private func commandW(in window: NSWindow) throws -> NSEvent { + private func command(_ key: String, _ flags: NSEvent.ModifierFlags = [], keyCode: UInt16, in window: NSWindow) throws -> NSEvent { try XCTUnwrap(NSEvent.keyEvent( - with: .keyDown, location: .zero, modifierFlags: [.command], timestamp: 0, windowNumber: window.windowNumber, - context: nil, characters: "w", charactersIgnoringModifiers: "w", isARepeat: false, keyCode: 13 + with: .keyDown, location: .zero, modifierFlags: flags.union(.command), timestamp: 0, windowNumber: window.windowNumber, + context: nil, characters: key, charactersIgnoringModifiers: key, isARepeat: false, keyCode: keyCode )) } @@ -108,19 +108,41 @@ final class LittleWindowTests: XCTestCase { } } - func testCommandWInALittleWindowClosesItNotATabBehind() async throws { + func testCommandWInALittleWindowClosesItNotATabBehind() throws { let tab = try XCTUnwrap(controller.createTabStateFirst(url: URL(string: "https://example.com/behind"))) let little = try openPage() - let event = try commandW(in: little.window) - XCTAssertFalse(controller.handleMonitoredKeyboardEvent(event), "the panel keeps the key its menu answer needs") - little.closeCurrentTab(nil) + XCTAssertTrue(controller.handleMonitoredKeyboardEvent(try command("w", keyCode: 13, in: little.window)), + "the page never sees the key") XCTAssertFalse(little.window.isVisible) XCTAssertTrue(controller.littleWindows.isEmpty) XCTAssertNotNil(controller.tabManager.tab(for: tab.id), "the tab in the browser window behind stays open") } + func testShiftCommandWInALittleWindowClosesItNotTheBrowserWindow() throws { + let little = try openPage() + + XCTAssertTrue(controller.handleMonitoredKeyboardEvent(try command("w", .shift, keyCode: 13, in: little.window))) + + XCTAssertFalse(little.window.isVisible) + XCTAssertTrue(controller.littleWindows.isEmpty) + XCTAssertTrue(browserContext.context.windows.windows.contains { $0 === controller }, "the browser window stays open") + } + + func testABrowserShortcutInALittleWindowStillActsOnTheBrowserWindow() throws { + _ = try XCTUnwrap(controller.createTabStateFirst(url: URL(string: "https://example.com/first"))) + let last = try XCTUnwrap(controller.createTabStateFirst(url: URL(string: "https://example.com/last"))) + let first = try XCTUnwrap(controller.tabManager.currentTabs.first { !$0.isClosed }) + controller.activateTabStateFirst(id: last.id) + let little = try openPage() + + XCTAssertTrue(controller.handleMonitoredKeyboardEvent(try command("1", keyCode: 18, in: little.window))) + + XCTAssertEqual(controller.tabManager.activeTabId, first.id) + XCTAssertTrue(little.window.isVisible) + } + func testEscapeClosesAPageWindowWhileThePageHasTheKeyboard() throws { let little = try openPage() little.chromeDidLoad()