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..b645a56d9 100644 --- a/Lilo/Window/MainWindowController+Input.swift +++ b/Lilo/Window/MainWindowController+Input.swift @@ -407,7 +407,7 @@ 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, + // 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 @@ -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 1fa5d49c8..157fe7735 100644 --- a/LiloTests/LittleWindow/LittleWindowTests.swift +++ b/LiloTests/LittleWindow/LittleWindowTests.swift @@ -49,6 +49,13 @@ final class LittleWindowTests: XCTestCase { )) } + private func command(_ key: String, _ flags: NSEvent.ModifierFlags = [], keyCode: UInt16, in window: NSWindow) throws -> NSEvent { + try XCTUnwrap(NSEvent.keyEvent( + with: .keyDown, location: .zero, modifierFlags: flags.union(.command), timestamp: 0, windowNumber: window.windowNumber, + context: nil, characters: key, charactersIgnoringModifiers: key, isARepeat: false, keyCode: keyCode + )) + } + func testNewLittleWindowOpensTheStartCardOutsideTheTabList() throws { let tabs = controller.tabManager.openTabs.count @@ -101,6 +108,41 @@ final class LittleWindowTests: XCTestCase { } } + func testCommandWInALittleWindowClosesItNotATabBehind() throws { + let tab = try XCTUnwrap(controller.createTabStateFirst(url: URL(string: "https://example.com/behind"))) + let little = try openPage() + + 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()