fix: match provider picker to action popup

This commit is contained in:
2026-10-18 00:05:46 +02:00
parent 11e604e79e
commit d829565188
5 changed files with 99 additions and 29 deletions
@@ -15,7 +15,9 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
ActionEntry(title: "Copy Emoji", symbol: "doc.on.doc", color: SunsetPalette.text),
ActionEntry(title: "Change source language…", symbol: "character.bubble", color: SunsetPalette.text),
ActionEntry(title: "Change target language…", symbol: "character.bubble", color: SunsetPalette.text),
ActionEntry(title: "Swap languages", symbol: "arrow.left.arrow.right", color: SunsetPalette.text)
ActionEntry(title: "Swap languages", symbol: "arrow.left.arrow.right", color: SunsetPalette.text),
ActionEntry(title: "MyMemory (no key)", symbol: "checkmark", color: SunsetPalette.text),
ActionEntry(title: "OpenAI · gpt-6-luna", symbol: "checkmark", color: SunsetPalette.text)
]
private var visibleEntries: [Int] = []
private var availableEntries = Array(0..<6)
@@ -41,6 +43,8 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
var changeSourceLanguage: (() -> Void)?
var changeTargetLanguage: (() -> Void)?
var swapLanguages: (() -> Void)?
var selectProvider: ((Bool) -> Void)?
private var currentProviderEntry: Int?
var closed: (() -> Void)?
var isShown: Bool { viewIfLoaded?.superview != nil && !isClosing }
@@ -143,9 +147,22 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
searchAccessibilityLabel: "Search translation actions")
}
func showProviders(selectedOpenAI: Bool, relativeTo anchor: NSView) {
currentProviderEntry = selectedOpenAI ? 11 : 10
show(title: "Translation provider", relativeTo: anchor, available: [10, 11],
searchAccessibilityLabel: "Search translation providers", belowAnchor: true)
if isShown {
selectedEntry = currentProviderEntry
updateSelection()
}
}
private func show(title: String, relativeTo anchor: NSView, available: [Int], emoji: Bool = false,
searchAccessibilityLabel: String = "Search application actions") {
if isShown { close(); return }
searchAccessibilityLabel: String = "Search application actions", belowAnchor: Bool = false) {
if viewIfLoaded?.superview != nil {
if isShown, availableEntries == available { close(); return }
close(animated: false)
}
guard let window = anchor.window, let host = window.contentView else { return }
let pill = anchor.superview ?? anchor
_ = view
@@ -163,6 +180,13 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
])
favorite.button.setAccessibilityLabel(favoriteTitle)
favorite.icon.image = NSImage(systemSymbolName: isFavorite ? "star.fill" : "star", accessibilityDescription: nil)
for index in [10, 11] {
entries[index].icon.isHidden = currentProviderEntry != index
}
search.placeholderAttributedString = NSAttributedString(
string: belowAnchor ? "Search for providers…" : "Search for actions…",
attributes: [.foregroundColor: SunsetPalette.secondaryText,
.font: NSFont.systemFont(ofSize: LauncherRowView.textSize)])
search.stringValue = ""
controlTextDidChange(Notification(name: NSControl.textDidChangeNotification))
transitionGeneration += 1
@@ -182,16 +206,18 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
])
NSLayoutConstraint.activate([
view.trailingAnchor.constraint(equalTo: pill.trailingAnchor),
view.bottomAnchor.constraint(equalTo: pill.bottomAnchor)
belowAnchor
? view.topAnchor.constraint(equalTo: pill.bottomAnchor, constant: 8)
: view.bottomAnchor.constraint(equalTo: pill.bottomAnchor)
])
coveredPill = pill
coveredPill = belowAnchor ? nil : pill
coveredPillAlpha = pill.alphaValue
}
pill.setAccessibilityHidden(true)
coveredPill?.setAccessibilityHidden(true)
NSAnimationContext.runAnimationGroup { context in
context.duration = NSWorkspace.shared.accessibilityDisplayShouldReduceMotion ? 0 : 0.16
view.animator().alphaValue = 1
pill.animator().alphaValue = 0
coveredPill?.animator().alphaValue = 0
}
window.makeFirstResponder(search)
(search.currentEditor() as? NSTextView)?.insertionPointColor = SunsetPalette.accent
@@ -271,7 +297,8 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
let selected = selectedEntry == index
entries[index].view.isSelected = selected
entries[index].returnKey.isHidden = !selected
entries[index].button.setAccessibilityValue(selected ? "Selected" : "Not selected")
let current = currentProviderEntry == index ? ", Current provider" : ""
entries[index].button.setAccessibilityValue((selected ? "Selected" : "Not selected") + current)
}
}
@@ -310,6 +337,8 @@ final class ApplicationActionsController: NSViewController, NSSearchFieldDelegat
case 7: changeSourceLanguage?()
case 8: changeTargetLanguage?()
case 9: swapLanguages?()
case 10: selectProvider?(false)
case 11: selectProvider?(true)
default: break
}
}