feat(panel): close with Esc without a click and render Markdown
Esc: make the panel key when shown (closeWithEscape, default on) without activating the app; the source app stays frontmost and Replace still targets it. Handle Esc with SwiftUI's exit command, which also works from the popover and after clicking controls. Add TranslationPanel.canBecomeKey and amend ADR-009.\n\nMarkdown: add MarkdownPresentation in SprachmittlerText (Foundation inline parser plus a conservative block parser for headings, lists, quotes, fenced code and rules), a SwiftUI MarkdownTranslationView, and a renderMarkdown setting (default on). JSON, HTML and code sources are never rendered; only http/https links open; images become alt text; Copy and Replace keep the raw Markdown (ADR-021).\n\nVerified: make verify green; synthetic Esc closes the panel and closes an open language popover first; a live Markdown translation rendered heading, bold/italic, inline code, list, quote, code block and link; Copy returned the raw Markdown; Replace still changed the TextEdit selection with the panel key.
This commit is contained in:
1 parent
d126124f97
commit
a3e544fbe4
22 files changed
+1072
-250
No files matched your search
@@ -61,6 +61,10 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
public var showSourcePreview: Bool
|
||||
/// Translation text size in points (12–28).
|
||||
public var translationFontSize: Int
|
||||
/// Render Markdown formatting in the translation panel.
|
||||
public var renderMarkdown: Bool
|
||||
/// Make the panel key when shown so Esc and the shortcuts work without a click.
|
||||
public var closeWithEscape: Bool
|
||||
/// Reflect the login-item setting.
|
||||
public var launchAtLogin: Bool
|
||||
/// Keep the last translation in memory for the panel.
|
||||
@@ -94,6 +98,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
autoCopy = false
|
||||
showSourcePreview = true
|
||||
translationFontSize = 17
|
||||
renderMarkdown = true
|
||||
closeWithEscape = true
|
||||
launchAtLogin = false
|
||||
keepRecentTranslationInMemory = true
|
||||
hasCompletedOnboarding = false
|
||||
@@ -235,8 +241,9 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
case endpoint, allowRemoteEndpoint, model, fastModel, targetLanguage, recentTargetLanguages
|
||||
case doubleCopyWindowMs, maxCharactersLatin, maxCharactersCJK, numCtx, numPredict
|
||||
case temperature, topP, topK, repeatPenalty, keepModelLoaded, warmUpOnLaunch
|
||||
case promptVariantPolicy, autoCopy, showSourcePreview, translationFontSize, launchAtLogin
|
||||
case keepRecentTranslationInMemory, hasCompletedOnboarding, settingsVersion
|
||||
case promptVariantPolicy, autoCopy, showSourcePreview, translationFontSize, renderMarkdown
|
||||
case closeWithEscape, launchAtLogin, keepRecentTranslationInMemory, hasCompletedOnboarding
|
||||
case settingsVersion
|
||||
}
|
||||
|
||||
/// Decodes with v0 migration: missing or unknown fields fall back to defaults, and an old
|
||||
@@ -276,8 +283,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
let keep = try container.decodeIfPresent(String.self, forKey: .keepModelLoaded)
|
||||
?? defaults.keepModelLoaded
|
||||
keepModelLoaded = ["5m", "30m", "1h", "0"].contains(keep) ? keep : defaults.keepModelLoaded
|
||||
warmUpOnLaunch = try container.decodeIfPresent(Bool.self, forKey: .warmUpOnLaunch)
|
||||
?? defaults.warmUpOnLaunch
|
||||
warmUpOnLaunch = try container.decodeIfPresent(Bool.self, forKey: .warmUpOnLaunch) ?? defaults.warmUpOnLaunch
|
||||
let policy = try container.decodeIfPresent(PromptVariantPolicy.self, forKey: .promptVariantPolicy)
|
||||
?? defaults.promptVariantPolicy
|
||||
promptVariantPolicy = policy
|
||||
@@ -285,8 +291,9 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
autoCopy = false
|
||||
showSourcePreview = try container.decodeIfPresent(Bool.self, forKey: .showSourcePreview)
|
||||
?? defaults.showSourcePreview
|
||||
launchAtLogin = try container.decodeIfPresent(Bool.self, forKey: .launchAtLogin)
|
||||
?? defaults.launchAtLogin
|
||||
renderMarkdown = try container.decodeIfPresent(Bool.self, forKey: .renderMarkdown) ?? defaults.renderMarkdown
|
||||
closeWithEscape = try container.decodeIfPresent(Bool.self, forKey: .closeWithEscape) ?? defaults.closeWithEscape
|
||||
launchAtLogin = try container.decodeIfPresent(Bool.self, forKey: .launchAtLogin) ?? defaults.launchAtLogin
|
||||
keepRecentTranslationInMemory = try container.decodeIfPresent(
|
||||
Bool.self,
|
||||
forKey: .keepRecentTranslationInMemory
|
||||
@@ -319,6 +326,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
try container.encode(autoCopy, forKey: .autoCopy)
|
||||
try container.encode(showSourcePreview, forKey: .showSourcePreview)
|
||||
try container.encode(translationFontSize, forKey: .translationFontSize)
|
||||
try container.encode(renderMarkdown, forKey: .renderMarkdown)
|
||||
try container.encode(closeWithEscape, forKey: .closeWithEscape)
|
||||
try container.encode(launchAtLogin, forKey: .launchAtLogin)
|
||||
try container.encode(keepRecentTranslationInMemory, forKey: .keepRecentTranslationInMemory)
|
||||
try container.encode(hasCompletedOnboarding, forKey: .hasCompletedOnboarding)
|
||||
|
||||
Reference in new issue
Block a user