feat(workspace): focus mode — recession, hover reveal, soft caret centering (#87)
Map #21 build child. Toggle via View menu / ⌘⇧F; panes and toolbar recede, overlay hover reveal (left: rail+library, right: mentor), soft caret centering while typing, loud save failure, ⌘S armed in focus. Full suite green; calibration gate #88 judges calm.
This commit is contained in:
1 parent
99aa3d2faf
commit
b0ab800d3d
12 files changed
+550
-98
No files matched your search
@@ -52,8 +52,10 @@ struct PostEditorView: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
toolbar
|
||||
Rectangle().fill(DesignTokens.border).frame(height: 1)
|
||||
if showsToolbar {
|
||||
toolbar
|
||||
Rectangle().fill(DesignTokens.border).frame(height: 1)
|
||||
}
|
||||
if reading {
|
||||
ReadingSurface(
|
||||
text: renderText,
|
||||
@@ -73,7 +75,38 @@ struct PostEditorView: View {
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(DesignTokens.surface)
|
||||
.background(focusGround)
|
||||
// #21: ⌘S stays armed in focus too — drafts have no autosave; the
|
||||
// trigger is invisible either way, so it lives here, not in the
|
||||
// receding toolbar.
|
||||
.background {
|
||||
Button("") { saveNow() }
|
||||
.keyboardShortcut("s", modifiers: .command)
|
||||
.opacity(0)
|
||||
.frame(width: 1, height: 1)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
// #21: save failure is LOUD in focus — the full unfocused widget
|
||||
// (dot + "Save failed") reappears, floating at the top edge where
|
||||
// the toolbar row stood. Autosave keeps running underneath.
|
||||
.overlay(alignment: .top) {
|
||||
if gate.isFocused, session?.saveState == .failed {
|
||||
HStack(spacing: 7) {
|
||||
Circle()
|
||||
.fill(DesignTokens.accent)
|
||||
.frame(width: 6, height: 6)
|
||||
Text("Save failed")
|
||||
}
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(DesignTokens.accent)
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 7)
|
||||
.background(DesignTokens.surface.opacity(0.96), in: RoundedRectangle(cornerRadius: DesignTokens.radius))
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel("Save state: Save failed")
|
||||
.transition(.move(edge: .top).combined(with: .opacity))
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if draftMirror.isEmpty {
|
||||
draftMirror = draftText ?? ""
|
||||
@@ -102,6 +135,17 @@ struct PostEditorView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// #21: the toolbar row recedes in focus (unless failure is loud).
|
||||
private var showsToolbar: Bool {
|
||||
!gate.isFocused || session?.saveState == .failed
|
||||
}
|
||||
|
||||
/// #21: focus runs on the workspace background, not the surface card —
|
||||
/// the centered measure on the workspace ground is all that remains.
|
||||
private var focusGround: Color {
|
||||
gate.isFocused ? DesignTokens.background : DesignTokens.surface
|
||||
}
|
||||
|
||||
/// The text reading renders: live session text or the draft mirror.
|
||||
private var renderText: String {
|
||||
session?.text ?? draftMirror
|
||||
@@ -110,9 +154,9 @@ struct PostEditorView: View {
|
||||
@ViewBuilder
|
||||
private var editingSurface: some View {
|
||||
if let session {
|
||||
ProseTextView(session: session, spellChecking: gate.spellChecking, caretHint: flipBackCaret)
|
||||
ProseTextView(session: session, spellChecking: gate.spellChecking, focused: gate.isFocused, caretHint: flipBackCaret)
|
||||
} else {
|
||||
ProseTextView(draft: draftMirror, spellChecking: gate.spellChecking, onEdit: { newText in
|
||||
ProseTextView(draft: draftMirror, spellChecking: gate.spellChecking, focused: gate.isFocused, onEdit: { newText in
|
||||
draftMirror = newText
|
||||
draftEdited?(newText)
|
||||
}, caretHint: flipBackCaret)
|
||||
@@ -175,12 +219,6 @@ struct PostEditorView: View {
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
// #64: ⌘S stays immediate in both modes — invisible trigger.
|
||||
Button("") { saveNow() }
|
||||
.keyboardShortcut("s", modifiers: .command)
|
||||
.opacity(0)
|
||||
.frame(width: 1, height: 1)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.frame(minHeight: 40)
|
||||
@@ -242,26 +280,32 @@ struct ProseTextView: NSViewRepresentable {
|
||||
var draft: String?
|
||||
var onEdit: ((String) -> Void)?
|
||||
var spellChecking = false
|
||||
/// #21: focus mode — the text ground joins the workspace background.
|
||||
var focused = false
|
||||
var caretHint: (location: Int, token: Int)?
|
||||
|
||||
init(
|
||||
session: EditorSession,
|
||||
spellChecking: Bool = false,
|
||||
focused: Bool = false,
|
||||
caretHint: (location: Int, token: Int)? = nil,
|
||||
) {
|
||||
self.session = session
|
||||
self.spellChecking = spellChecking
|
||||
self.focused = focused
|
||||
self.caretHint = caretHint
|
||||
}
|
||||
|
||||
init(
|
||||
draft: String,
|
||||
spellChecking: Bool = false,
|
||||
focused: Bool = false,
|
||||
onEdit: @escaping (String) -> Void,
|
||||
caretHint: (location: Int, token: Int)? = nil,
|
||||
) {
|
||||
self.draft = draft
|
||||
self.spellChecking = spellChecking
|
||||
self.focused = focused
|
||||
self.onEdit = onEdit
|
||||
self.caretHint = caretHint
|
||||
}
|
||||
@@ -287,7 +331,9 @@ struct ProseTextView: NSViewRepresentable {
|
||||
// #77: squiggles follow the posture toggle (default off).
|
||||
tv.isContinuousSpellCheckingEnabled = spellChecking
|
||||
tv.usesFindBar = true
|
||||
tv.backgroundColor = NSColor.white
|
||||
// #21: focus ground joins the workspace background; drawsBackground
|
||||
// stays true either way (white in the unfocused card).
|
||||
tv.backgroundColor = focused ? DesignTokens.workspaceBackground : NSColor.white
|
||||
tv.typingAttributes = ProseTypography.bodyAttributes
|
||||
tv.delegate = context.coordinator
|
||||
tv.layoutManager?.allowsNonContiguousLayout = true
|
||||
@@ -310,7 +356,7 @@ struct ProseTextView: NSViewRepresentable {
|
||||
// out at rest (iOS-like), instead of always occupying the right edge.
|
||||
scroll.scrollerStyle = .overlay
|
||||
scroll.drawsBackground = true
|
||||
scroll.backgroundColor = NSColor.white
|
||||
scroll.backgroundColor = focused ? DesignTokens.workspaceBackground : NSColor.white
|
||||
context.coordinator.textView = tv
|
||||
context.coordinator.sessionRef = session // strong: both die with the editor
|
||||
return scroll
|
||||
@@ -320,6 +366,11 @@ struct ProseTextView: NSViewRepresentable {
|
||||
guard let tv = scroll.documentView as? NSTextView else { return }
|
||||
// #77: posture toggle while editing — cheap idempotent set.
|
||||
tv.isContinuousSpellCheckingEnabled = spellChecking
|
||||
// #21: the ground follows focus in/out without a remount.
|
||||
let ground = focused ? DesignTokens.workspaceBackground : NSColor.white
|
||||
tv.backgroundColor = ground
|
||||
scroll.backgroundColor = ground
|
||||
context.coordinator.focused = focused
|
||||
if let session {
|
||||
context.coordinator.sessionRef = session
|
||||
// Load only when the generation moved (open, Yes-reload) — never
|
||||
@@ -383,6 +434,9 @@ struct ProseTextView: NSViewRepresentable {
|
||||
var sessionRef: EditorSession?
|
||||
var loadedGeneration = -1
|
||||
var appliedCaretToken = -1
|
||||
/// #21: focus posture mirror — soft centering applies while typing
|
||||
/// in focus only.
|
||||
var focused = false
|
||||
/// #77: fence delimiter count — the cross-paragraph fence state
|
||||
/// fingerprint. A moved count means a ``` was typed/deleted and every
|
||||
/// line until the matching delimiter changed kind.
|
||||
@@ -409,6 +463,11 @@ struct ProseTextView: NSViewRepresentable {
|
||||
tv.setSelectedRange(selected)
|
||||
}
|
||||
tv.typingAttributes = ProseTypography.bodyAttributes
|
||||
// #21: soft caret centering — typing only, never scrollback or
|
||||
// drag-selection (the reader never gets fought).
|
||||
if focused {
|
||||
CaretCentering.centerCaretWhileTyping(textView: tv)
|
||||
}
|
||||
if let sessionRef {
|
||||
sessionRef.edit(storage.string)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user