Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ public final class CanvasModel {
let panelIds = layout.panelIds(in: paneID),
let currentIndex = panelIds.firstIndex(of: panel),
!panelIds.isEmpty else { return false }
// `currentIndex + offset` traps on extreme offsets (Int.max/.min), so
// saturate the addition before clamping to the valid index range.
let (sum, overflowed) = currentIndex.addingReportingOverflow(offset)
let target = overflowed ? (offset > 0 ? Int.max : Int.min) : sum
let destinationIndex = min(
max(currentIndex + offset, panelIds.startIndex),
max(target, panelIds.startIndex),
panelIds.index(before: panelIds.endIndex)
)
guard destinationIndex != currentIndex else { return true }
Expand Down
8 changes: 6 additions & 2 deletions Sources/HostSettingsActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ final class HostSettingsActions: SettingsHostActions {
}

func notifyShortcutSettingsDidChange() {
KeyboardShortcutSettings.settingsFileStore.reload()
KeyboardShortcutSettings.notifySettingsFileDidChange()
// reload() posts didChangeNotification itself when it observes a
// change; posting again here would double-notify observers.
let reloadDidNotify = KeyboardShortcutSettings.settingsFileStore.reload()
if !reloadDidNotify {
KeyboardShortcutSettings.notifySettingsFileDidChange()
}
}

func applyLanguageOverride(_ language: AppLanguage) {
Expand Down
11 changes: 9 additions & 2 deletions Sources/KeyboardShortcutSettingsFileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ final class CmuxSettingsFileStore {
}
}

func reload() {
/// Returns whether the reload observed a settings change and already
/// posted `KeyboardShortcutSettings.didChangeNotification`, so callers
/// that notify unconditionally can avoid posting a duplicate.
@discardableResult
func reload() -> Bool {
reload(
applyLiveDefaultSideEffects: true,
synchronizeManagedAppearanceTerminalTheme: true
Expand All @@ -145,10 +149,11 @@ final class CmuxSettingsFileStore {
applyManagedDefaultBatchSideEffects(drainDeferredManagedDefaultSideEffects())
}

@discardableResult
private func reload(
applyLiveDefaultSideEffects: Bool,
synchronizeManagedAppearanceTerminalTheme: Bool
) {
) -> Bool {
let previousState = synchronized {
(
shortcuts: shortcutsByAction,
Expand Down Expand Up @@ -183,7 +188,9 @@ final class CmuxSettingsFileStore {
|| previousState.whenClauses != resolved.whenClauses
|| previousState.sourcePath != resolved.path {
KeyboardShortcutSettings.notifySettingsFileDidChange(center: notificationCenter)
return true
}
return false
}

func override(for action: KeyboardShortcutSettings.Action) -> StoredShortcut? {
Expand Down