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:
schihei committed 2026-11-26 15:26:30 +01:00
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)
@@ -30,6 +30,10 @@ public struct PanelConfiguration: Sendable, Equatable {
public var showSourcePreview: Bool
/// Translation text size in points.
public var translationFontSize: Int
/// Render Markdown formatting for Markdown sources.
public var renderMarkdown: Bool
/// Make the panel key when shown so Esc works without a click.
public var closeWithEscape: Bool
/// Recent targets, most recent first.
public var recentTargets: [ModelLanguage]
@@ -41,6 +45,8 @@ public struct PanelConfiguration: Sendable, Equatable {
sampling: SamplingOptions = .publisherDefault,
showSourcePreview: Bool = true,
translationFontSize: Int = 17,
renderMarkdown: Bool = true,
closeWithEscape: Bool = true,
recentTargets: [ModelLanguage] = []
) {
self.target = target
@@ -49,6 +55,8 @@ public struct PanelConfiguration: Sendable, Equatable {
self.sampling = sampling
self.showSourcePreview = showSourcePreview
self.translationFontSize = translationFontSize
self.renderMarkdown = renderMarkdown
self.closeWithEscape = closeWithEscape
self.recentTargets = recentTargets
}
}