Add copy-on-select preference (#2282)

This commit is contained in:
Austin Wang 2026-03-29 18:16:05 -07:00 committed by GitHub
parent 94cc865e83
commit 35cb42fbc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 178 additions and 14 deletions

View file

@ -3785,6 +3785,22 @@ enum CommandPaletteRenameSelectionSettings {
}
}
enum TerminalCopyOnSelectSettings {
static let enabledKey = "terminalCopyOnSelectEnabled"
static let defaultEnabled = false
static func isEnabled(defaults: UserDefaults = .standard) -> Bool {
if defaults.object(forKey: enabledKey) == nil {
return defaultEnabled
}
return defaults.bool(forKey: enabledKey)
}
static func overrideConfigLine(defaults: UserDefaults = .standard) -> String {
isEnabled(defaults: defaults) ? "copy-on-select = clipboard" : "copy-on-select = false"
}
}
enum CommandPaletteSwitcherSearchSettings {
static let searchAllSurfacesKey = "commandPalette.switcherSearchAllSurfaces"
static let defaultSearchAllSurfaces = false
@ -3869,6 +3885,8 @@ struct SettingsView: View {
@AppStorage(QuitWarningSettings.warnBeforeQuitKey) private var warnBeforeQuitShortcut = QuitWarningSettings.defaultWarnBeforeQuit
@AppStorage(CommandPaletteRenameSelectionSettings.selectAllOnFocusKey)
private var commandPaletteRenameSelectAllOnFocus = CommandPaletteRenameSelectionSettings.defaultSelectAllOnFocus
@AppStorage(TerminalCopyOnSelectSettings.enabledKey)
private var terminalCopyOnSelectEnabled = TerminalCopyOnSelectSettings.defaultEnabled
@AppStorage(CommandPaletteSwitcherSearchSettings.searchAllSurfacesKey)
private var commandPaletteSearchAllSurfaces = CommandPaletteSwitcherSearchSettings.defaultSearchAllSurfaces
@AppStorage(ShortcutHintDebugSettings.alwaysShowHintsKey)
@ -3990,6 +4008,19 @@ struct SettingsView: View {
)
}
private var terminalCopyOnSelectSubtitle: String {
if terminalCopyOnSelectEnabled {
return String(
localized: "settings.app.copyOnSelect.subtitleOn",
defaultValue: "Automatically copy selected terminal text to the system clipboard."
)
}
return String(
localized: "settings.app.copyOnSelect.subtitleOff",
defaultValue: "Selecting terminal text does not copy it to the system clipboard."
)
}
private var selectedSidebarActiveTabIndicatorStyle: SidebarActiveTabIndicatorStyle {
SidebarActiveTabIndicatorSettings.resolvedStyle(rawValue: sidebarActiveTabIndicatorStyle)
}
@ -4511,6 +4542,20 @@ struct SettingsView: View {
SettingsCardDivider()
SettingsCardRow(
String(localized: "settings.app.copyOnSelect", defaultValue: "Copy on Select"),
subtitle: terminalCopyOnSelectSubtitle
) {
Toggle("", isOn: $terminalCopyOnSelectEnabled)
.labelsHidden()
.controlSize(.small)
.accessibilityLabel(
String(localized: "settings.app.copyOnSelect", defaultValue: "Copy on Select")
)
}
SettingsCardDivider()
SettingsCardRow(
String(localized: "settings.app.reorderOnNotification", defaultValue: "Reorder on Notification"),
subtitle: String(localized: "settings.app.reorderOnNotification.subtitle", defaultValue: "Move workspaces to the top when they receive a notification. Disable for stable shortcut positions.")
@ -5654,6 +5699,9 @@ struct SettingsView: View {
.onChange(of: notificationSoundCustomFilePath) { _, _ in
refreshNotificationCustomSoundStatus()
}
.onChange(of: terminalCopyOnSelectEnabled) { _, _ in
GhosttyApp.shared.reloadConfiguration(source: "settings.copy_on_select")
}
.onChange(of: browserInsecureHTTPAllowlist) { oldValue, newValue in
// Keep draft in sync with external changes unless the user has local unsaved edits.
if browserInsecureHTTPAllowlistDraft == oldValue {
@ -5777,6 +5825,7 @@ struct SettingsView: View {
showMenuBarExtra = MenuBarExtraSettings.defaultShowInMenuBar
warnBeforeQuitShortcut = QuitWarningSettings.defaultWarnBeforeQuit
commandPaletteRenameSelectAllOnFocus = CommandPaletteRenameSelectionSettings.defaultSelectAllOnFocus
terminalCopyOnSelectEnabled = TerminalCopyOnSelectSettings.defaultEnabled
commandPaletteSearchAllSurfaces = CommandPaletteSwitcherSearchSettings.defaultSearchAllSurfaces
ShortcutHintDebugSettings.resetVisibilityDefaults()
alwaysShowShortcutHints = ShortcutHintDebugSettings.defaultAlwaysShowHints