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
@@ -2,16 +2,17 @@ import AppKit
|
||||
import SprachmittlerCore
|
||||
import SwiftUI
|
||||
|
||||
/// The non-activating floating panel. It never activates the app or steals focus.
|
||||
/// The non-activating floating panel. It never activates the app. While visible it can be the key
|
||||
/// window so Esc and the keyboard shortcuts work without a click.
|
||||
@MainActor
|
||||
final class PanelController: NSObject, NSWindowDelegate {
|
||||
private let panel: NSPanel
|
||||
private let panel: TranslationPanel
|
||||
private let viewModel: PanelViewModel
|
||||
|
||||
/// Creates the panel and its SwiftUI content.
|
||||
init(viewModel: PanelViewModel) {
|
||||
self.viewModel = viewModel
|
||||
panel = NSPanel(
|
||||
panel = TranslationPanel(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 540, height: 520),
|
||||
styleMask: [.titled, .fullSizeContentView, .nonactivatingPanel],
|
||||
backing: .buffered,
|
||||
@@ -21,7 +22,7 @@ final class PanelController: NSObject, NSWindowDelegate {
|
||||
panel.delegate = self
|
||||
panel.isFloatingPanel = true
|
||||
panel.isMovable = true
|
||||
panel.becomesKeyOnlyIfNeeded = true
|
||||
panel.becomesKeyOnlyIfNeeded = false
|
||||
panel.level = .floating
|
||||
panel.hidesOnDeactivate = false
|
||||
panel.isMovableByWindowBackground = true
|
||||
@@ -50,6 +51,9 @@ final class PanelController: NSObject, NSWindowDelegate {
|
||||
positionNearMouse()
|
||||
}
|
||||
panel.orderFrontRegardless()
|
||||
if viewModel.configuration.closeWithEscape {
|
||||
panel.makeKey()
|
||||
}
|
||||
}
|
||||
|
||||
/// Hides the panel and cancels/releases its content.
|
||||
|
||||
Reference in new issue
Block a user