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
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ public final class CanvasModel {
let panelIds = layout.panelIds(in: paneID),
let currentIndex = panelIds.firstIndex(of: panel),
!panelIds.isEmpty else { return false }
// `offset` may be Int.min/Int.max; saturate instead of trapping.
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
9 changes: 7 additions & 2 deletions Sources/HostSettingsActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ final class HostSettingsActions: SettingsHostActions {
}

func notifyShortcutSettingsDidChange() {
KeyboardShortcutSettings.settingsFileStore.reload()
KeyboardShortcutSettings.notifySettingsFileDidChange()
// reload() already posts didChangeNotification when the file's
// contents changed; posting again here double-notified every
// listener. Only post when the reload saw no change, so callers
// still get exactly one notification either way.
if !KeyboardShortcutSettings.settingsFileStore.reload() {
KeyboardShortcutSettings.notifySettingsFileDidChange()
}
}

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

func reload() {
/// Returns whether the reload posted `didChangeNotification`, so callers
/// that must guarantee a notification can post one without double-firing.
@discardableResult
func reload() -> Bool {
reload(
applyLiveDefaultSideEffects: true,
synchronizeManagedAppearanceTerminalTheme: true
Expand All @@ -145,10 +148,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 +187,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
Loading