Skip to content
Open
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
46 changes: 35 additions & 11 deletions Copy/App/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ final class AppCoordinator {
hideDuringScreenSharing: settings.hideDuringScreenSharing,
compactShelf: settings.compactShelf,
theme: settings.shelfTheme,
floatingShelf: settings.floatingShelf) { [weak self] in
floatingShelf: settings.floatingShelf,
miniShelfSize: settings.miniShelfSize.size) { [weak self] in
guard let self else { return NSView() }
let host = ShelfHostingView(rootView: ShelfRootView(viewModel: self.shelfViewModel))
// Drags onto the pinboard tabs (cards to file, tabs to reorder) are tracked by
Expand Down Expand Up @@ -96,6 +97,8 @@ final class AppCoordinator {
event.modifierFlags.intersection([.command, .option, .control]).isEmpty,
let chars = event.charactersIgnoringModifiers, chars.count == 1,
let first = chars.first, first.isLetter {
// The mini shelf searches only once its lens button opens the field.
if viewModel.isMiniShelf && !viewModel.miniSearchShown { return true }
viewModel.updateSearchText(viewModel.searchQuery.text + (event.characters ?? chars))
viewModel.focusSearchRequested = true
return true
Expand Down Expand Up @@ -124,6 +127,8 @@ final class AppCoordinator {
(1...9).contains(digitValue) {
if digitValue == 1 {
viewModel.selectTab(.history)
} else if viewModel.isMiniShelf && !viewModel.miniShowsPinboards {
// No pinboard column showing, so no board to switch to.
} else {
let index = digitValue - 2
if viewModel.pinboards.indices.contains(index), let id = viewModel.pinboards[index].id {
Expand All @@ -148,15 +153,25 @@ final class AppCoordinator {
// never falls through to the plain ⌘V paste action below.
let shortcutModifiers = event.modifierFlags.intersection([.command, .option, .control, .shift])
switch event.keyCode {
case 123: // left arrow
// The mini shelf lists its items top to bottom; its left/right arrows stay with
// the search field.
case 125 where viewModel.isMiniShelf: // down arrow
viewModel.moveSelection(1)
return true
case 126 where viewModel.isMiniShelf: // up arrow
viewModel.moveSelection(-1)
return true
case 123 where !viewModel.isMiniShelf: // left arrow
viewModel.moveSelection(-1)
return true
case 124: // right arrow
case 124 where !viewModel.isMiniShelf: // right arrow
viewModel.moveSelection(1)
return true
case 53: // escape
if viewModel.previewShown {
viewModel.previewShown = false
} else if viewModel.miniSearchShown {
viewModel.closeMiniSearch()
} else if !viewModel.searchQuery.isEmpty {
viewModel.clearSearch()
} else {
Expand Down Expand Up @@ -468,6 +483,9 @@ final class AppCoordinator {
settings.onCompactShelfChange = { [weak self] compact in
self?.shelfController.setCompactShelf(compact)
}
settings.onMiniShelfSizeChange = { [weak self] size in
self?.shelfController.setMiniShelfSize(size.size)
}
settings.onShelfThemeChange = { [weak self] theme in
self?.shelfController.setTheme(theme)
self?.pasteStackController.setTheme(theme)
Expand Down Expand Up @@ -626,19 +644,26 @@ final class AppCoordinator {
/// `shelfViewModel`/`shelfController` are both created once and reused for the
/// app's lifetime, so without this the permission banner would only ever reflect
/// whatever was true the very first time the shelf ever appeared.
func toggleShelf() {
if !shelfController.isVisible {
shelfViewModel.refreshPermissionState()
/// `mode` nil opens the one chosen in Settings (`SettingsStore.shelfMode`).
func toggleShelf(mode: ShelfMode? = nil) {
if shelfController.isVisible {
shelfController.hide(restoreFocus: true)
} else {
showShelf(mode: mode ?? settings.shelfMode)
}
shelfController.toggle()
}

private func showShelf(mode: ShelfMode) {
shelfViewModel.refreshPermissionState()
shelfViewModel.prepareToShow(mini: mode == .mini)
shelfController.show(mode: mode)
}

/// Opens the shelf (if not already open) and immediately shows `CreateItemSheet`,
/// for the status menu's "New Item…" action.
func newItem() {
if !shelfController.isVisible {
shelfViewModel.refreshPermissionState()
shelfController.show()
showShelf(mode: settings.shelfMode)
}
shelfViewModel.beginCreate()
}
Expand Down Expand Up @@ -671,8 +696,7 @@ final class AppCoordinator {
/// the user presses the hotkey again to actually advance once the shelf is visible.
func selectNextPinboard() {
guard shelfController.isVisible else {
shelfViewModel.refreshPermissionState()
shelfController.show()
showShelf(mode: settings.shelfMode)
return
}
let pinboards = shelfViewModel.pinboards
Expand Down
7 changes: 7 additions & 0 deletions Copy/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Sparkle

extension KeyboardShortcuts.Name {
static let toggleShelf = Self("toggleShelf", initial: .init(.v, modifiers: [.command, .shift]))
/// No default shortcut — the user opts in from Settings. Opens whichever shelf
/// `toggleShelf` doesn't (`SettingsStore.shelfMode`), so both stay a keystroke away.
static let toggleAlternateShelf = Self("toggleAlternateShelf")
static let togglePasteStack = Self("togglePasteStack", initial: .init(.c, modifiers: [.command, .shift]))
static let pasteNextFromStack = Self("pasteNextFromStack", initial: .init(.n, modifiers: [.control, .option, .command]))
/// No default shortcut — the user opts in from Settings. Pastes the most recent
Expand Down Expand Up @@ -161,6 +164,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
KeyboardShortcuts.onKeyDown(for: .toggleShelf) { [weak self] in
self?.coordinator.toggleShelf()
}
KeyboardShortcuts.onKeyDown(for: .toggleAlternateShelf) { [weak self] in
guard let coordinator = self?.coordinator else { return }
coordinator.toggleShelf(mode: coordinator.settings.shelfMode.other)
}
KeyboardShortcuts.onKeyDown(for: .togglePasteStack) { [weak self] in
self?.coordinator.togglePasteStack()
}
Expand Down
23 changes: 23 additions & 0 deletions Copy/Settings/GeneralSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ struct GeneralSettings: View {

var body: some View {
Form {
Section {
Picker("Shelf Layout", selection: $settings.shelfMode) {
ForEach(ShelfMode.allCases) { mode in Text(mode.title).tag(mode) }
}
.pickerStyle(.segmented)
Picker("Mini Shelf Size", selection: $settings.miniShelfSize) {
ForEach(MiniShelfSize.allCases) { size in Text(size.title).tag(size) }
}
.pickerStyle(.segmented)
// Only applies while the layout is Mini.
.disabled(settings.shelfMode == .full)
} footer: {
Text(settings.shelfMode == .full
? "Open Copy shows the full shelf along the bottom of the screen. Set a shortcut for the mini shelf in Shortcuts."
: "Open Copy shows the mini shelf above the text cursor, or at the pointer when the app doesn't report one. Set a shortcut for the full shelf in Shortcuts.")
.font(.footnote)
.foregroundStyle(.secondary)
}

Section {
Picker("Shelf Size", selection: $settings.compactShelf) {
Text("Standard").tag(false)
Text("Compact").tag(true)
}
.pickerStyle(.segmented)
// Only applies while the layout is Full.
.disabled(settings.shelfMode == .mini)
} footer: {
Text("Compact shows smaller cards so more fit in the shelf at once.")
.font(.footnote)
Expand All @@ -39,6 +60,8 @@ struct GeneralSettings: View {
Text("Floating").tag(true)
}
.pickerStyle(.segmented)
// Only applies while the layout is Full.
.disabled(settings.shelfMode == .mini)
} footer: {
Text("Floating adds space around the shelf and rounds every corner.")
.font(.footnote)
Expand Down
64 changes: 64 additions & 0 deletions Copy/Settings/SettingsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,45 @@ enum ShelfTheme: String, CaseIterable, Identifiable {
}
}

/// Which shelf the Open Copy hotkey opens: the full-width shelf at the screen's edge, or
/// the mini shelf above the text cursor.
enum ShelfMode: String, CaseIterable, Identifiable {
case full, mini
var id: Self { self }
var title: String { self == .full ? "Full" : "Mini" }
var other: ShelfMode { self == .full ? .mini : .full }
}

/// The mini shelf's three sizes, and how many lines of each card's text they show.
enum MiniShelfSize: String, CaseIterable, Identifiable {
case small, medium, large
var id: Self { self }

var title: String {
switch self {
case .small: return "Small"
case .medium: return "Medium"
case .large: return "Large"
}
}

var size: CGSize {
switch self {
case .small: return CGSize(width: 280, height: 320)
case .medium: return CGSize(width: 340, height: 400)
case .large: return CGSize(width: 400, height: 480)
}
}

var previewLines: Int {
switch self {
case .small: return 1
case .medium: return 2
case .large: return 3
}
}
}

/// How long unfavorited, unpinned history items are kept before pruning.
enum RetentionPeriod: String, CaseIterable {
case unlimited
Expand Down Expand Up @@ -159,6 +198,8 @@ final class SettingsStore {
static let hideSecretsKey = "hideSecrets"
static let secretLifetimeKey = "secretLifetime"
static let pasteStackExternalAccessKey = "pasteStackExternalAccessEnabled"
static let shelfModeKey = "shelfMode"
static let miniShelfSizeKey = "miniShelfSize"

var retention: RetentionPeriod {
didSet {
Expand Down Expand Up @@ -255,6 +296,26 @@ final class SettingsStore {
}
@ObservationIgnored var onFloatingShelfChange: ((Bool) -> Void)?

/// Which shelf the Open Copy hotkey opens. Full by default. The other one has its own
/// optional hotkey (`KeyboardShortcuts.Name.toggleAlternateShelf`).
var shelfMode: ShelfMode {
didSet {
guard shelfMode != oldValue else { return }
defaults.set(shelfMode.rawValue, forKey: Self.shelfModeKey)
}
}

/// Pushed to the panel controller by `onMiniShelfSizeChange`, which resizes an open
/// mini shelf in place.
var miniShelfSize: MiniShelfSize {
didSet {
guard miniShelfSize != oldValue else { return }
defaults.set(miniShelfSize.rawValue, forKey: Self.miniShelfSizeKey)
onMiniShelfSizeChange?(miniShelfSize)
}
}
@ObservationIgnored var onMiniShelfSizeChange: ((MiniShelfSize) -> Void)?

/// Masks secrets on cards, previews and titles (`SecretDetector`). Display only: the
/// stored and pasted text is unchanged.
var hideSecrets: Bool {
Expand Down Expand Up @@ -388,6 +449,9 @@ final class SettingsStore {
favoritesEnabled = (defaults.object(forKey: Self.favoritesEnabledKey) as? Bool) ?? true
floatingShelf = (defaults.object(forKey: Self.floatingShelfKey) as? Bool) ?? false
compactShelf = (defaults.object(forKey: Self.compactShelfKey) as? Bool) ?? false
shelfMode = defaults.string(forKey: Self.shelfModeKey).flatMap(ShelfMode.init(rawValue:)) ?? .full
miniShelfSize = defaults.string(forKey: Self.miniShelfSizeKey)
.flatMap(MiniShelfSize.init(rawValue:)) ?? .medium
if let raw = defaults.string(forKey: Self.shelfThemeKey), let saved = ShelfTheme(rawValue: raw) {
shelfTheme = saved
} else {
Expand Down
2 changes: 2 additions & 0 deletions Copy/Settings/ShortcutsSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct ShortcutsSettings: View {
KeyboardShortcuts.Recorder("Open Copy:", name: .toggleShelf) { _ in
settings.onShelfHotkeyChange?()
}
KeyboardShortcuts.Recorder(settings.shelfMode == .full ? "Open Mini Shelf:" : "Open Full Shelf:",
name: .toggleAlternateShelf)
KeyboardShortcuts.Recorder("Paste Stack:", name: .togglePasteStack)
KeyboardShortcuts.Recorder("Quick Paste Latest:", name: .quickPasteLatest)
KeyboardShortcuts.Recorder("Next Pinboard:", name: .nextPinboard)
Expand Down
Loading
Loading