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
2 changes: 1 addition & 1 deletion .github/hub-ratchet-baseline.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"MenuValidationContext stored properties": 86,
"menu validation `case #selector` arms": 116,
"menu validation `case #selector` arms": 115,
"ShortcutAction cases": 98,
"TabType cases": 9,
"SettingsPane cases": 12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ struct MenuValidationContext: Equatable {
var hasDatabaseFilter = false
var canFilterSchemas = false
var hasSchemaFilter = false
var canZoomIn = false
var canZoomOut = false
}

extension MainSplitViewController: NSMenuItemValidation {
Expand Down Expand Up @@ -418,11 +416,6 @@ extension MainSplitViewController: NSMenuItemValidation {
/// connection and something that can hold a selection, not merely a window.
case #selector(clearSelection(_:)): return context.isConnected

/// The window's zoom changes the editor font, an app setting that needs no session. A focused
/// diagram claims these first.
case #selector(zoomIn(_:)): return context.canZoomIn
case #selector(zoomOut(_:)): return context.canZoomOut

default: return isAgentSessionCommandEnabled(selector, context: context)
}
}
Expand Down Expand Up @@ -604,7 +597,6 @@ extension MainSplitViewController: NSMenuItemValidation {
/// command actions, so read from them, the one command that reaches its composer was dimmed.
var menuValidationContext: MenuValidationContext {
let conversations = assistantConversationModel
let typography = AppSettingsManager.shared.typography
guard let actions = commandActions else {
return MenuValidationContext(
hasSelectedWorkspace: workspaces.selectedConnectionId != nil,
Expand All @@ -615,9 +607,7 @@ extension MainSplitViewController: NSMenuItemValidation {
canFocusAssistant: canFocusAssistant,
canMoveTabToConnection: canMoveSelectedTabToConnection,
hasOtherWindowTabs: hasOtherWindowTabs,
canToggleWorkspaceRail: canToggleWorkspaceRail,
canZoomIn: typography.editorFontSize(zoomedBy: 1) != nil,
canZoomOut: typography.editorFontSize(zoomedBy: -1) != nil
canToggleWorkspaceRail: canToggleWorkspaceRail
)
}
return MenuValidationContext(
Expand Down Expand Up @@ -705,9 +695,7 @@ extension MainSplitViewController: NSMenuItemValidation {
canFavoriteActiveDatabase: actions.canFavoriteActiveDatabase,
hasDatabaseFilter: actions.hasDatabaseFilter,
canFilterSchemas: actions.canFilterSchemas,
hasSchemaFilter: actions.hasSchemaFilter,
canZoomIn: typography.editorFontSize(zoomedBy: 1) != nil,
canZoomOut: typography.editorFontSize(zoomedBy: -1) != nil
hasSchemaFilter: actions.hasSchemaFilter
)
}

Expand All @@ -725,6 +713,9 @@ extension MainSplitViewController: NSMenuItemValidation {
if action == #selector(setSafeModeLevel(_:)) { return canChooseSafeModeLevel(menuItem) }
if action == #selector(requestDisconnect) { return canDisconnect }
if action == #selector(retryConnection) { return canReconnect }
if let zoom = Self.zoomEnablement(action, typography: AppSettingsManager.shared.typography) {
return zoom
}
return Self.isEnabled(action, context: menuValidationContext(naming: menuItem))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ extension MainSplitViewController: ZoomCommandResponding {
adjustEditorTextSize(by: -1)
}

/// Nil for any other command. The size is the app's setting, not this window's, so it is read
/// live instead of through the captured validation context.
static func zoomEnablement(_ action: Selector, typography: TypographySettings) -> Bool? {
if action == #selector(zoomIn(_:)) { return typography.editorFontSize(zoomedBy: 1) != nil }
if action == #selector(zoomOut(_:)) { return typography.editorFontSize(zoomedBy: -1) != nil }
return nil
}

private func adjustEditorTextSize(by delta: Int) {
var typography = AppSettingsManager.shared.typography
guard let size = typography.editorFontSize(zoomedBy: delta) else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private let liveValidatedSelectors: Set<Selector> = [
#selector(MainSplitViewController.toggleContentModeFromMenu(_:)),
#selector(MainSplitViewController.requestDisconnect),
#selector(MainSplitViewController.retryConnection),
#selector(MainSplitViewController.zoomIn(_:)),
#selector(MainSplitViewController.zoomOut(_:)),
]

@MainActor
Expand Down
20 changes: 12 additions & 8 deletions TableProTests/Models/Settings/EditorZoomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ struct EditorZoomTests {
let zoomIn = #selector(MainSplitViewController.zoomIn(_:))
let zoomOut = #selector(MainSplitViewController.zoomOut(_:))

var context = MenuValidationContext()
context.canZoomOut = true
#expect(MainSplitViewController.resolvedEnablement(zoomIn, context: context) == false)
#expect(MainSplitViewController.resolvedEnablement(zoomOut, context: context) == true)
let middle = TypographySettings(editorFontSize: 13)
let largest = TypographySettings(editorFontSize: TypographySettings.sizeRange.upperBound)
let smallest = TypographySettings(editorFontSize: TypographySettings.sizeRange.lowerBound)

#expect(MainSplitViewController.zoomEnablement(zoomIn, typography: middle) == true)
#expect(MainSplitViewController.zoomEnablement(zoomOut, typography: middle) == true)
#expect(MainSplitViewController.zoomEnablement(zoomIn, typography: largest) == false)
#expect(MainSplitViewController.zoomEnablement(zoomOut, typography: largest) == true)
#expect(MainSplitViewController.zoomEnablement(zoomIn, typography: smallest) == true)
#expect(MainSplitViewController.zoomEnablement(zoomOut, typography: smallest) == false)

context.canZoomIn = true
context.canZoomOut = false
#expect(MainSplitViewController.resolvedEnablement(zoomIn, context: context) == true)
#expect(MainSplitViewController.resolvedEnablement(zoomOut, context: context) == false)
let other = #selector(MainSplitViewController.clearSelection(_:))
#expect(MainSplitViewController.zoomEnablement(other, typography: middle) == nil)
}
}
Loading