Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20261201-195120.765461.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion Lilo/Window/MainWindowController+Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions LiloTests/LittleWindow/LittleWindowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Loading