Skip to content
Open
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
23 changes: 21 additions & 2 deletions Sources/Pesty/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,15 @@ final class AppController: NSObject, NSApplicationDelegate, NSWindowDelegate {
return nil
case kVK_Return, kVK_ANSI_KeypadEnter:
pasteSelected(); return nil
case kVK_LeftArrow, kVK_UpArrow:
case kVK_LeftArrow:
if cmd { moveBarSection(by: -1) } else { store.moveSelection(by: -1) }
return nil
case kVK_RightArrow:
if cmd { moveBarSection(by: 1) } else { store.moveSelection(by: 1) }
return nil
case kVK_UpArrow:
store.moveSelection(by: -1); return nil
case kVK_RightArrow, kVK_DownArrow:
case kVK_DownArrow:
store.moveSelection(by: 1); return nil
case kVK_Delete:
if cmd { deleteEffectiveSelection(); return nil }
Expand Down Expand Up @@ -565,6 +571,19 @@ final class AppController: NSObject, NSApplicationDelegate, NSWindowDelegate {
return event
}

/// Cycles the same sources, in the same order, that the tab bar presents.
/// The plus button is intentionally excluded: it creates a new pinboard
/// rather than representing a navigable section.
private func moveBarSection(by delta: Int) {
let sources: [BarSource] = [.history] + store.pinboards.map { .pinboard($0.id) }
guard !sources.isEmpty else { return }

let currentIndex = sources.firstIndex(of: store.source) ?? 0
let nextIndex = (currentIndex + delta % sources.count + sources.count) % sources.count
store.source = sources[nextIndex]
store.selectFirst()
}

private static func quickPasteDigit(for keyCode: Int) -> Int? {
switch keyCode {
case kVK_ANSI_1, kVK_ANSI_Keypad1: return 1
Expand Down
Loading