From c0e2848cb5df480afb25dbf3d909c63c69f4978d Mon Sep 17 00:00:00 2001 From: Mitsuki Fukunaga Date: Fri, 4 Dec 2026 15:25:31 +1100 Subject: [PATCH 1/4] fix: show a callout's title text while its marker is concealed --- src/webview/cm/decorations/block-style.ts | 47 ++++--- .../cm/decorations/callout-marker-conceal.ts | 95 ++++++++------ src/webview/cm/decorations/callout.ts | 85 ++++++++---- src/webview/cm/decorations/shared.ts | 18 +++ src/webview/cm/theme.ts | 11 +- .../callout-title-row.browser.test.ts | 121 ++++++++++++++++++ .../cm-decoration-block-style.test.ts | 27 +++- ...-decoration-callout-marker-conceal.test.ts | 81 +++++++++++- 8 files changed, 389 insertions(+), 96 deletions(-) create mode 100644 test/webview-browser/callout-title-row.browser.test.ts diff --git a/src/webview/cm/decorations/block-style.ts b/src/webview/cm/decorations/block-style.ts index f726e29a..589a93d4 100644 --- a/src/webview/cm/decorations/block-style.ts +++ b/src/webview/cm/decorations/block-style.ts @@ -77,9 +77,10 @@ // quote (calloutTypeForOutermost) so a nested `> >` inner marker never double-emits // a second type class — the container type wins. When the caret is INSIDE the block // the `[!TYPE]` marker row is REVEALED and gets `quoll-callout-marker` (header -// weight); when OUTSIDE, the marker StateField conceals the whole row and this -// module migrates the rounded `-open` corner onto the first -// VISIBLE body line via the same-source `calloutMarkerConceal` predicate. The +// weight); when OUTSIDE, the marker StateField conceals the marker — a titled row +// stays visible as the title row (still `quoll-callout-marker`), while an untitled +// row is hidden whole and this module migrates the rounded `-open` corner onto the +// first VISIBLE body line via the same-source `calloutMarkerConceal` span. The // `[!TYPE]` marker stays literal editable text (decoration-only, byte-identical // round-trip); an unrecognised token (`[!FOO]`) matches nothing → generic panel. // @@ -108,9 +109,10 @@ // contribute to quollSyntaxExclusionZones: frontmatter-field (its span is // `---`-fenced, so it never parses as FencedCode / Blockquote — this gate is // indeed cheap insurance for it) and callout-marker-conceal (concealed `[!TYPE]` -// rows ARE Blockquote syntax — the point-exclusion here is load-bearing: it skips -// the concealed row and migrates the rounded `-open` corner to the first visible -// body line; see callout-marker-conceal.ts:7-13). A shared union helper +// rows ARE Blockquote syntax — the exclusion here is load-bearing: it skips an +// untitled concealed row, whose zone covers the whole line, and the corner migrates +// to the first visible body line; a TITLED row's zone ends at the title, so +// `lineInExclusionZone` keeps styling it; see callout-marker-conceal.ts header). A shared union helper // (Codex Conf 86) is deferred — it would also touch list-hang-indent, out of // this PR's 1-purpose scope. // @@ -163,7 +165,7 @@ import { hasBlockquoteAncestor, } from "./callout.js"; import { quollSyntaxExclusionZones } from "./orchestrator.js"; -import { pointInExclusionZone } from "./shared.js"; +import { lineInExclusionZone } from "./shared.js"; import type { BuildContext } from "./types.js"; /** Persistent Lezer node type — the `.node` of an iterate cursor. Derived from @@ -386,7 +388,7 @@ function buildBlockLineDecorations( const toLine = doc.lineAt(clampTo - 1).number; for (let n = fromLine; n <= toLine; n++) { const line = doc.line(n); - if (pointInExclusionZone(line.from, zones)) { + if (lineInExclusionZone(line.from, line.to, zones)) { continue; } const classes = classesForLine(n); @@ -559,18 +561,20 @@ function buildBlockquoteRuleWithBoundaryInfo( // (unknown / plain / nested-inner) → no callout class → the generic Phase-1 panel. const calloutType = calloutTypeForOutermost(doc, node.node); // When the caret is OUTSIDE the callout, the marker StateField conceals the - // `[!TYPE]` row (collapsed to zero height, whole line published to the exclusion - // facet). `markerConcealed` is derived from the SAME single-source predicate the - // StateField uses, on the SAME state, so the two can never disagree. - const markerConcealed = calloutMarkerConceal(doc, ctx.selection, node.node) !== null; - // Migrate the rounded edge off a concealed boundary fence OR a concealed callout - // marker onto the adjacent visible line. Start one line inward when the marker - // is concealed (it collapses to zero height), then walk past any remaining + // `[!TYPE]` marker. An UNTITLED row is hidden whole (collapsed to zero height, + // whole line published to the exclusion facet); a TITLED row hides only the + // marker and stays visible as the title row. `markerRowHidden` is derived from + // the SAME single-source span the StateField uses, on the SAME state, so the two + // can never disagree. + const markerRowHidden = calloutMarkerConceal(doc, ctx.selection, node.node)?.hidesLine === true; + // Migrate the rounded edge off a concealed boundary fence OR a hidden callout + // marker row onto the adjacent visible line. Start one line inward when the + // marker row is hidden (it collapses to zero height), then walk past any remaining // concealed rows — a concealed LEADING fence collapses too (the callout body // starts with a fenced block; caret outside the callout ⇒ outside the fence), so // the visible top edge is the first non-concealed body line. This subsumes the // fence-only single step: for a non-callout with a concealed open fence - // `markerConcealed` is false → start at nodeFirstLine, then the loop steps once + // `markerRowHidden` is false → start at nodeFirstLine, then the loop steps once // (identical to the previous single check). closeLine is UNCHANGED. // // No `hasConcealableMarker` gate is added on blockquoteRule for this: the callout @@ -578,7 +582,7 @@ function buildBlockquoteRuleWithBoundaryInfo( // rebuilds on the exclusion-facet identity change that a conceal↔reveal flip // produces (R2). Contrast the fence case, whose conceal is NOT facet-published → // it genuinely needs the explicit `hasBoundaryFence` selectionSet gate. - let openLine = markerConcealed ? nodeFirstLine + 1 : nodeFirstLine; + let openLine = markerRowHidden ? nodeFirstLine + 1 : nodeFirstLine; while (openLine < nodeLastLine && isConcealed(openLine)) { openLine += 1; } @@ -606,10 +610,11 @@ function buildBlockquoteRuleWithBoundaryInfo( } if (calloutType !== null) { out.push(CALLOUT_CLASS, calloutClassForType(calloutType)); - // The concealed marker line is skipped by buildBlockLineDecorations - // (facet-excluded), so this only fires on a REVEALED marker row — the - // `!markerConcealed` guard keeps the header class off the migrated row. - if (n === nodeFirstLine && !markerConcealed) { + // A hidden marker row is skipped by buildBlockLineDecorations + // (facet-excluded), so this only fires on a VISIBLE marker row (revealed, + // or concealed down to its title) — the `!markerRowHidden` guard keeps the + // header class off the migrated row. + if (n === nodeFirstLine && !markerRowHidden) { out.push(CALLOUT_MARKER_CLASS); } } diff --git a/src/webview/cm/decorations/callout-marker-conceal.ts b/src/webview/cm/decorations/callout-marker-conceal.ts index d7795aaa..e901456b 100644 --- a/src/webview/cm/decorations/callout-marker-conceal.ts +++ b/src/webview/cm/decorations/callout-marker-conceal.ts @@ -1,23 +1,25 @@ -// StateField that CONCEALS the `[!TYPE]` marker row of a callout when the caret is +// StateField that CONCEALS the `[!TYPE]` marker of a callout when the caret is // OUTSIDE the whole callout block (mirrors fenced-code-collapse.ts's rebuild-on- -// selection template). Per concealed marker line it emits, over the WHOLE line: -// - Decoration.line({ class: CALLOUT_MARKER_HIDDEN_CLASS }) — the zero-height -// collapse (the theme copies `.quoll-fenced-code-fence-hidden`), and -// - Decoration.replace({}) over [line.from, line.to) — hides the row content, -// and publishes [line.from, line.to] to quollSyntaxExclusionZones so: -// - the orchestrator's arbitrate() drops EVERY inline reveal decoration on that -// line (the leading `>`, inline marks, links) → exactly ONE replace covers the -// row, with no overlapping-replace crash surface (v2 Finding 2); and -// - block-style.ts skips the concealed marker line (buildBlockLineDecorations -// point-excludes it) and migrates the rounded `-open` corner -// onto the first visible body line. +// selection template). The concealed span is `calloutConcealSpan` (callout.ts): from +// the marker line's start to where the title text starts. Per concealed marker it +// emits ONE Decoration.replace({}) over that span and publishes the SAME span to +// quollSyntaxExclusionZones, so: +// - the orchestrator's arbitrate() drops EVERY inline reveal decoration overlapping +// it (the leading `>`, anything inside the marker) → exactly ONE replace covers +// the marker, with no overlapping-replace crash surface (v2 Finding 2). Inline +// marks in the title (`**title**`) start at or after the span end, so they stay; +// - an UNTITLED row (the span is the whole line) also gets +// Decoration.line({ class: CALLOUT_MARKER_HIDDEN_CLASS }) — the zero-height +// collapse (the theme copies `.quoll-fenced-code-fence-hidden`) — and block-style +// skips that line (the zone covers it whole) and migrates the rounded `-open` +// corner onto the first visible body line. A TITLED row stays visible as the +// callout's title row and keeps its corner (REV-20261203-15). // -// A StateField (NOT an inline reveal provider) because a marker line can carry -// inline markup (`> [!TIP] **title**`): an inline provider hiding only the -// `[!TYPE]` run while blockquote-reveal independently hides the `>` would leave TWO -// overlapping Decoration.replace on the line → CodeMirror throws and blanks the -// whole set. Owning the whole line as ONE replace + publishing the zone is the -// single-replace design (CLAUDE.md callout invariant + the plan's crash regression). +// A StateField (NOT an inline reveal provider) because the conceal is BLOCK-scoped +// (a caret anywhere in the callout reveals it) and its span must be published as an +// exclusion zone: that is what arbitrates blockquote-reveal's own `>` hide away, so +// ONE replace owns `>` + marker and no second replace can overlap it (the plan's +// crash regression, `> [!TIP] **title**`). // // Display-only: never mutates bytes → the `[!TYPE]` source round-trips identically. // The concealed row is a NON-atomic inline replace, so its byte positions stay @@ -32,21 +34,24 @@ import { Decoration, type DecorationSet, EditorView } from "@codemirror/view"; import { type Interval, intersects, mergeIntervals } from "../bounded-recompute.js"; import { hostDocumentReseed } from "../host-reseed.js"; import { expandToEnclosingBlock, requiresFullBoundedRebuild } from "../structural-guard.js"; -import { CALLOUT_MARKER_HIDDEN_CLASS, calloutTypeForOutermost } from "./callout.js"; +import { CALLOUT_MARKER_HIDDEN_CLASS, calloutConcealSpan } from "./callout.js"; import { quollSyntaxExclusionZones } from "./orchestrator.js"; import { intersectsAnySelection } from "./shared.js"; type Zone = { from: number; to: number }; +type Marker = Zone & { hidesLine: boolean }; /** Selection-INDEPENDENT facts about one outermost callout that HAS a body (a * marker-only callout is never a record — it never conceals). `markerFrom` is * both the block's first-line start AND the concealed marker span's start; + * [markerFrom, markerTo) + `hidesLine` are `calloutConcealSpan`'s result; * `blockTo` is the block's last CONTENT line end (`doc.lineAt(node.to - 1).to`, * robust to a Lezer `to` overshoot per [[quoll-lezer-table-to-overshoots-trailing-line]]). * The selection-dependent conceal decision is applied later in `deriveMarkers`. */ interface CalloutRecord { markerFrom: number; markerTo: number; + hidesLine: boolean; blockTo: number; } @@ -56,7 +61,7 @@ interface ConcealState { records: readonly CalloutRecord[]; /** Concealed marker-line spans for the CURRENT selection, doc-ordered. Compared on * a selection-only move to keep `prev` verbatim (F3). */ - markers: readonly Zone[]; + markers: readonly Marker[]; decorations: DecorationSet; /** Published exclusion zones — same content as `markers`, a distinct field so the * facet provider returns a stable reference whenever `update` keeps `prev` (F3). */ @@ -84,15 +89,19 @@ function buildRange(state: EditorState, rangeFrom: number, rangeTo: number): Cal from: rangeFrom, to: rangeTo, enter: (node) => { - if (node.name !== "Blockquote" || calloutTypeForOutermost(doc, node.node) === null) { + if (node.name !== "Blockquote") { return; } - const firstLine = doc.lineAt(node.from); - const lastLine = doc.lineAt(node.to - 1); - if (lastLine.number === firstLine.number) { - return; // marker-only callout: never a record (never conceals) + const span = calloutConcealSpan(doc, node.node); // null: not a callout / marker-only + if (span === null) { + return; } - out.push({ markerFrom: firstLine.from, markerTo: firstLine.to, blockTo: lastLine.to }); + out.push({ + markerFrom: span.from, + markerTo: span.to, + hidesLine: span.hidesLine, + blockTo: doc.lineAt(node.to - 1).to, + }); }, }); return out; @@ -144,7 +153,12 @@ function computeBoundedRecords( byMarker.set(rec.markerFrom, rec); } else { // Position shift only: block structure unchanged (untouched + outside span). - byMarker.set(newFrom, { markerFrom: newFrom, markerTo, blockTo: newTo }); + byMarker.set(newFrom, { + markerFrom: newFrom, + markerTo, + hidesLine: rec.hidesLine, + blockTo: newTo, + }); } } } @@ -161,28 +175,31 @@ function computeBoundedRecords( * [markerFrom, blockTo] — identical to `calloutBlockRevealed` / `calloutMarkerConceal` * in callout.ts (the marker-only + not-a-callout cases are already excluded at * record-build time). Records are doc-ordered, so markers come out doc-ordered. */ -function deriveMarkers(records: readonly CalloutRecord[], state: EditorState): Zone[] { - const markers: Zone[] = []; +function deriveMarkers(records: readonly CalloutRecord[], state: EditorState): Marker[] { + const markers: Marker[] = []; for (const rec of records) { if (!intersectsAnySelection(state.selection, rec.markerFrom, rec.blockTo)) { - markers.push({ from: rec.markerFrom, to: rec.markerTo }); + markers.push({ from: rec.markerFrom, to: rec.markerTo, hidesLine: rec.hidesLine }); } } return markers; } -/** The per-marker line-deco + replace share the SAME line.from; a RangeSetBuilder - * REJECTS a replace added before a line decoration at the same pos (line decos have - * a lower startSide). `Decoration.set(_, true)` sorts them so CM accepts the pair. */ -function buildDecorations(markers: readonly Zone[]): DecorationSet { - const ranges = markers.flatMap((m) => [ - Decoration.line({ class: CALLOUT_MARKER_HIDDEN_CLASS }).range(m.from), - Decoration.replace({}).range(m.from, m.to), - ]); +/** An untitled marker's line-deco + replace share the SAME line.from; a + * RangeSetBuilder REJECTS a replace added before a line decoration at the same pos + * (line decos have a lower startSide). `Decoration.set(_, true)` sorts them so CM + * accepts the pair. */ +function buildDecorations(markers: readonly Marker[]): DecorationSet { + const ranges = markers.flatMap((m) => { + const replace = Decoration.replace({}).range(m.from, m.to); + return m.hidesLine + ? [Decoration.line({ class: CALLOUT_MARKER_HIDDEN_CLASS }).range(m.from), replace] + : [replace]; + }); return Decoration.set(ranges, true); } -function assemble(records: readonly CalloutRecord[], markers: readonly Zone[]): ConcealState { +function assemble(records: readonly CalloutRecord[], markers: readonly Marker[]): ConcealState { return { records, markers, diff --git a/src/webview/cm/decorations/callout.ts b/src/webview/cm/decorations/callout.ts index 78f8c381..8770e895 100644 --- a/src/webview/cm/decorations/callout.ts +++ b/src/webview/cm/decorations/callout.ts @@ -24,16 +24,19 @@ type SyntaxNode = Tree["topNode"]; * with the per-type `calloutClassForType` class that supplies the accent value. */ export const CALLOUT_CLASS = "quoll-callout"; -/** Class on the FIRST line of a callout (the `[!TYPE]` marker line) when it is - * REVEALED (caret inside the block). Drives the header font-weight in cm/theme.ts. - * When the marker row is CONCEALED it is skipped by block-style and this class is - * not emitted — the StateField's zero-height class takes over. */ +/** Class on the FIRST line of a callout (the `[!TYPE]` marker line) whenever that + * row is visible: REVEALED (caret inside the block), or concealed down to its title + * text. Drives the header font-weight in cm/theme.ts. When an untitled marker row is + * concealed it is skipped by block-style and this class is not emitted — the + * StateField's zero-height class takes over. */ export const CALLOUT_MARKER_CLASS = "quoll-callout-marker"; -/** Class on a CONCEALED marker line (caret OUTSIDE the callout block). Emitted by - * the callout-marker-conceal StateField, which replaces the whole marker row and - * collapses it to zero height via this class — the theme copies the five - * zero-height props of `.quoll-fenced-code-fence-hidden`. */ +/** Class on a CONCEALED UNTITLED marker line (caret OUTSIDE the callout block, and + * nothing but the marker on the row). Emitted by the callout-marker-conceal + * StateField, which replaces the whole marker row and collapses it to zero height + * via this class — the theme copies the five zero-height props of + * `.quoll-fenced-code-fence-hidden`. A titled row hides only its marker and stays + * visible, so it never carries this class. */ export const CALLOUT_MARKER_HIDDEN_CLASS = "quoll-callout-marker-hidden"; /** The five GitHub/Obsidian admonition types. A `[!TYPE]` first line inside a @@ -78,6 +81,14 @@ const CALLOUT_MARKER_RE = /^\[!(note|tip|important|warning|caution)\](?:[-+])?(? * against Lezer across a broad prefix battery. Pure — the sole input is the * first line's text. */ export function calloutTypeForLine(lineText: string): CalloutType | null { + return matchCalloutMarker(lineText)?.type ?? null; +} + +/** The `[!TYPE]` match of a blockquote first line (see `calloutTypeForLine` for the + * prefix grammar), with `markerEnd` = the offset in `lineText` just past the + * marker, its optional fold suffix and any spaces/tabs after it — i.e. where the + * title text starts (`lineText.length` when there is no title). */ +function matchCalloutMarker(lineText: string): { type: CalloutType; markerEnd: number } | null { let i = 0; let column = 0; // Up to 3 spaces of initial indent (spaces only; a leading tab reaches column 4 @@ -110,7 +121,14 @@ export function calloutTypeForLine(lineText: string): CalloutType | null { return null; // indented code block, not a marker } const m = CALLOUT_MARKER_RE.exec(lineText.slice(i)); - return m === null ? null : (m[1].toLowerCase() as CalloutType); + if (m === null) { + return null; + } + let markerEnd = i + m[0].length; + while (lineText[markerEnd] === " " || lineText[markerEnd] === "\t") { + markerEnd += 1; + } + return { type: m[1].toLowerCase() as CalloutType, markerEnd }; } /** True when `node` sits inside another Blockquote (a nested `> >` inner node). @@ -151,28 +169,45 @@ export function calloutBlockRevealed( return intersectsAnySelection(selection, doc.lineAt(node.from).from, doc.lineAt(node.to - 1).to); } -/** The marker line span `{from, to}` to CONCEAL for callout `node`, or null when - * the marker row must stay visible. null when: `node` is not an outermost callout - * (calloutTypeForOutermost null); OR the callout is marker-ONLY (no body line — - * concealing it would vanish the whole block, since the marker is the sole row); - * OR the block is revealed (a selection intersects it). Otherwise the first line's - * span. The SINGLE source of truth both block-style.ts and the StateField call so - * the `-open` corner migration and the conceal can never disagree. */ -export function calloutMarkerConceal( +/** The span a callout conceals while the caret is outside it: `{from, to}` from the + * marker line's start to where the title text starts (past the `[!TYPE]` match, its + * optional `+`/`-` fold suffix and the whitespace after it), plus `hidesLine` — true + * when nothing but whitespace follows the marker, so the whole row is hidden and + * collapses to zero height; false when a title follows and the row stays visible as + * the callout's title row. null when `node` is not an outermost callout, or the + * callout is marker-ONLY (no body line — concealing would leave nothing to show). + * Selection-INDEPENDENT; the ONE computation the conceal StateField's replace, its + * exclusion zone and block-style's corner migration all derive from. */ +export function calloutConcealSpan( doc: Text, - selection: EditorSelection, node: SyntaxNode -): { from: number; to: number } | null { - if (calloutTypeForOutermost(doc, node) === null) { +): { from: number; to: number; hidesLine: boolean } | null { + if (hasBlockquoteAncestor(node)) { return null; } const firstLine = doc.lineAt(node.from); - const lastLine = doc.lineAt(node.to - 1); - if (lastLine.number === firstLine.number) { - return null; // marker-only callout: NEVER conceal a bodyless callout + const match = matchCalloutMarker(firstLine.text); + if (match === null || doc.lineAt(node.to - 1).number === firstLine.number) { + return null; // not a callout, or marker-only: NEVER conceal a bodyless callout } - if (calloutBlockRevealed(doc, selection, node)) { + return { + from: firstLine.from, + to: firstLine.from + match.markerEnd, + hidesLine: match.markerEnd === firstLine.length, + }; +} + +/** {@link calloutConcealSpan} for the CURRENT selection: null when the block is + * revealed (a selection intersects it). The predicate block-style.ts calls, so the + * `-open` corner migration and the StateField's conceal can never disagree. */ +export function calloutMarkerConceal( + doc: Text, + selection: EditorSelection, + node: SyntaxNode +): { from: number; to: number; hidesLine: boolean } | null { + const span = calloutConcealSpan(doc, node); + if (span === null || calloutBlockRevealed(doc, selection, node)) { return null; } - return { from: firstLine.from, to: firstLine.to }; + return span; } diff --git a/src/webview/cm/decorations/shared.ts b/src/webview/cm/decorations/shared.ts index a4aebc3a..a9f66406 100644 --- a/src/webview/cm/decorations/shared.ts +++ b/src/webview/cm/decorations/shared.ts @@ -102,3 +102,21 @@ export function pointInExclusionZone( } return false; } + +/** Returns `true` when the line [`lineFrom`, `lineTo`] lies WHOLLY inside a zone — + * the "this row is hidden" question, for a consumer that styles a line's box. A + * zone that ends mid-line (a titled callout conceals only `> [!TYPE] `, leaving its + * title visible) does not cover the line. Agrees with `pointInExclusionZone` on + * every whole-line zone (frontmatter, an untitled callout marker row). */ +export function lineInExclusionZone( + lineFrom: number, + lineTo: number, + zones: readonly { from: number; to: number }[] +): boolean { + for (const z of zones) { + if (lineFrom >= z.from && lineFrom < z.to && lineTo <= z.to) { + return true; + } + } + return false; +} diff --git a/src/webview/cm/theme.ts b/src/webview/cm/theme.ts index 312c30d2..bea19775 100644 --- a/src/webview/cm/theme.ts +++ b/src/webview/cm/theme.ts @@ -638,7 +638,7 @@ export const blockStyleThemeSpec = { // nested/continuation `> > inner` open never carries it and no transparent strip splits // the parent panel — replacing the old rendered-sibling `:not(.quoll-blockquote + …)` // gate that CM virtualisation could misfire at the render edge. Callouts inherit this - // (their lines carry -blockquote-open too), and a concealed-marker callout migrates the + // (their lines carry -blockquote-open too), and a hidden untitled-marker callout migrates the // outer class onto the first visible body line exactly as -open migrates. The outer class // co-occurs with the base -open on the same line, so the compensated radii layer on top. ".cm-line.quoll-blockquote-outer-open": blockEdgeGapCorner("top"), @@ -691,14 +691,15 @@ export const blockStyleThemeSpec = { // (note=blue, tip=green, important=purple, warning=amber, caution=red). ".cm-line.quoll-callout": { boxShadow: calloutAccentBar }, ...calloutRuleSet(".cm-line"), - // The REVEALED marker line (the `[!TYPE]` line, caret inside the block) reads as - // a header — the accent bar + this weighted marker line carry the callout type, + // The VISIBLE marker line (the `[!TYPE]` line revealed with the caret inside the + // block, or a titled row concealed down to its title) reads as a header — the accent bar + this weighted marker line carry the callout type, // so no per-type emoji badge is painted (it was redundant on the minimal axis). ".cm-line.quoll-callout-marker": { fontWeight: "600", }, - // A CONCEALED marker line (caret OUTSIDE the callout): the callout-marker-conceal - // StateField replaces the whole `[!TYPE]` row and tags it with this class. + // A CONCEALED UNTITLED marker line (caret OUTSIDE the callout): the + // callout-marker-conceal StateField replaces the whole `[!TYPE]` row and tags it with + // this class (a titled row hides only its marker and never carries it). // Collapse it to zero height so no blank padded row remains — the `-open` corner // rides the first visible body line instead. Copies the five zero-height // props of `.quoll-fenced-code-fence-hidden` below. Placed NEXT to that rule but diff --git a/test/webview-browser/callout-title-row.browser.test.ts b/test/webview-browser/callout-title-row.browser.test.ts new file mode 100644 index 00000000..a775a8fa --- /dev/null +++ b/test/webview-browser/callout-title-row.browser.test.ts @@ -0,0 +1,121 @@ +// Real-Chromium gate for a TITLED callout's marker row (REV-20261203-15). With the caret +// outside, the conceal hides only `> [!TYPE] ` (plus any fold suffix), so the title row +// stays on screen and must keep the panel's rounded top corners + top padding — the +// corner may not migrate to the body line as it does for an untitled callout. happy-dom +// has no layout and drops calc() radii, so the painted facts live here. Each case also +// moves the caret into the body and back out, since the corner rides a selection-driven +// rebuild. + +import { markdown, markdownLanguage } from "@codemirror/lang-markdown"; +import { EditorSelection, EditorState } from "@codemirror/state"; +import { EditorView } from "@codemirror/view"; +import { afterEach, describe, expect, it } from "vitest"; +import { blockStyle } from "../../src/webview/cm/decorations/block-style.js"; +import { calloutMarkerConcealField } from "../../src/webview/cm/decorations/callout-marker-conceal.js"; +import { quollSyntaxReveal } from "../../src/webview/cm/decorations/index.js"; +import { quollBlockStyleTheme, quollCmLinePaddingTheme } from "../../src/webview/cm/theme.js"; +import { settled } from "./helpers/frames.js"; + +let view: EditorView | undefined; +afterEach(() => { + view?.destroy(); + view = undefined; + for (const n of document.body.querySelectorAll(".cm-callout-title-probe")) { + n.remove(); + } +}); + +function mount(doc: string, caret: number): EditorView { + const parent = document.createElement("div"); + parent.className = "cm-callout-title-probe"; + parent.style.width = "500px"; + document.body.appendChild(parent); + return new EditorView({ + state: EditorState.create({ + doc, + selection: EditorSelection.single(caret), + extensions: [ + markdown({ base: markdownLanguage }), + quollSyntaxReveal(), + blockStyle, + calloutMarkerConcealField, + quollCmLinePaddingTheme, + quollBlockStyleTheme, + ], + }), + parent, + }); +} + +const px = (s: string): number => Number.parseFloat(s || "0"); + +interface RowFacts { + text: string; + height: number; + topLeftRadius: number; + topRightRadius: number; + paddingTop: number; + bodyTopLeftRadius: number; +} + +function rowFacts(v: EditorView): RowFacts { + const rows = [...v.contentDOM.querySelectorAll(".cm-line")]; + const title = rows[0] as HTMLElement; + const body = rows[1] as HTMLElement; + const cs = getComputedStyle(title); + return { + text: title.textContent ?? "", + height: title.getBoundingClientRect().height, + topLeftRadius: px(cs.borderTopLeftRadius), + topRightRadius: px(cs.borderTopRightRadius), + paddingTop: px(cs.paddingTop), + bodyTopLeftRadius: px(getComputedStyle(body).borderTopLeftRadius), + }; +} + +const CASES: Array<[string, string, string]> = [ + ["plain title", "> [!WARNING] タイトル", "タイトル"], + ["fold suffix +", "> [!WARNING]+ heads up", "heads up"], + ["fold suffix -", "> [!WARNING]- heads up", "heads up"], + ["bold title", "> [!TIP] **bold title**", "bold title"], +]; + +describe("callout title row — painted corners and padding (real Chromium)", () => { + for (const [name, markerRow, title] of CASES) { + it(`${name}: the title row shows, keeps the top corners and padding, through a caret in/out`, async () => { + const doc = `${markerRow}\n> body\n\npara`; + const outside = doc.indexOf("para") + 1; + view = mount(doc, outside); + await settled(); + const before = rowFacts(view); + expect(before.text).toContain(title); + expect(before.text).not.toContain("[!"); + expect(before.text).not.toContain("**"); + expect(before.height).toBeGreaterThan(0); + expect(before.topLeftRadius).toBeGreaterThan(0); + expect(before.topRightRadius).toBeGreaterThan(0); + expect(before.paddingTop).toBeGreaterThan(0); + expect(before.bodyTopLeftRadius).toBe(0); + + view.dispatch({ selection: { anchor: doc.indexOf("body") + 1 } }); + await settled(); + const inside = rowFacts(view); + expect(inside.text).toContain("[!"); + expect(inside.topLeftRadius).toBe(before.topLeftRadius); + expect(inside.paddingTop).toBe(before.paddingTop); + + view.dispatch({ selection: { anchor: outside } }); + await settled(); + expect(rowFacts(view)).toEqual(before); + }); + } + + it("contrast: an untitled callout still hides its marker row and the body takes the corner", async () => { + const doc = "> [!WARNING]\n> body\n\npara"; + view = mount(doc, doc.indexOf("para") + 1); + await settled(); + const facts = rowFacts(view); + expect(facts.height).toBe(0); + expect(facts.bodyTopLeftRadius).toBeGreaterThan(0); + }); +}); diff --git a/test/webview/decorations/cm-decoration-block-style.test.ts b/test/webview/decorations/cm-decoration-block-style.test.ts index c2764840..63946395 100644 --- a/test/webview/decorations/cm-decoration-block-style.test.ts +++ b/test/webview/decorations/cm-decoration-block-style.test.ts @@ -613,15 +613,21 @@ describe("block-style — gating & clamping", () => { expect(lines(buildFencedCodePanel(ctx("just a paragraph")))).toEqual([]); }); - it("skips a line whose start is inside an exclusion zone", () => { - // "> a"[0,3] "> b"[4,7]; zone covers L1's start only. L2 (from=4) is the + it("skips a line an exclusion zone covers whole", () => { + // "> a"[0,3] "> b"[4,7]; the zone covers L1 whole. L2 (from=4) is the // Blockquote node's LAST line, so it still carries the -close modifier. - const set = buildBlockquoteRule(ctx("> a\n> b"), [{ from: 0, to: 1 }]); + const set = buildBlockquoteRule(ctx("> a\n> b"), [{ from: 0, to: 3 }]); expect(lines(set)).toEqual([ { from: 4, cls: "quoll-blockquote quoll-blockquote-close quoll-blockquote-outer-close" }, ]); }); + it("keeps styling a line a zone covers only partly (a titled callout's marker)", () => { + // The zone ends mid-L1, so L1 is still a visible row and keeps its classes. + const set = buildBlockquoteRule(ctx("> a\n> b"), [{ from: 0, to: 2 }]); + expect(lines(set).map((l) => l.from)).toEqual([0, 4]); + }); + it("clamps emission to visible ranges; caret in-block keeps body lines bare (both fences revealed)", () => { // Visible range = L2+L3 of the 4-line fence; default caret = 0 (in-block). // Both fences reveal, so neither body line takes a relocated edge. @@ -1405,6 +1411,21 @@ describe("block-style — callout marker conceal migrates -open (caret outside)" expect(out[0]?.cls).toContain("quoll-callout-note"); }); + // REV-20261203-15: a TITLED marker conceals only `> [!TYPE] ` (zone = that span), + // so the row stays visible as the title row and keeps -open + the header class. + it("caret outside, titled marker: the title row keeps -open + the header class", () => { + const doc = "> [!WARNING]+ heads up\n> body\n\npara"; + const ctxOutside = ctxCaret(doc, doc.indexOf("para") + 1); + const out = lines(buildBlockquoteRule(ctxOutside, [{ from: 0, to: doc.indexOf("heads") }])); + expect(out[0]?.from).toBe(0); + expect(out[0]?.cls).toContain("quoll-blockquote-open"); + expect(out[0]?.cls).toContain("quoll-blockquote-outer-open"); + expect(out[0]?.cls).toContain("quoll-callout-marker"); + expect(out[0]?.cls).toContain("quoll-callout-warning"); + const body = out.find((l) => l.from === ctxOutside.state.doc.line(2).from); + expect(body?.cls).not.toContain("quoll-blockquote-open"); + }); + // R3: the callout body STARTS with a fenced block. Caret outside ⇒ the marker row // AND the leading fence are both concealed, so -open must migrate PAST the // zero-height fence row onto the fence's first body line. diff --git a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts index 62fb2f48..0fa123ed 100644 --- a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts +++ b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts @@ -70,6 +70,7 @@ describe("calloutMarkerConceal — pure predicate", () => { expect(calloutMarkerConceal(state.doc, state.selection, node)).toEqual({ from: marker.from, to: marker.to, + hidesLine: true, }); }); @@ -109,10 +110,52 @@ describe("calloutMarkerConceal — pure predicate", () => { expect(calloutMarkerConceal(state.doc, state.selection, node)).toEqual({ from: marker.from, to: marker.to, + hidesLine: true, }); }); }); +describe("calloutMarkerConceal — a titled marker hides only the marker", () => { + // REV-20261203-15: the title text after `[!TYPE]` (and its optional fold suffix) is + // the callout's title row, so caret-outside hides [line start, title start) only. + const cases: Array<[string, string]> = [ + ["> [!WARNING] タイトル", "タイトル"], + [">[!NOTE] Title", "Title"], + [" > [!NOTE] Title", "Title"], + [">\t[!TIP] Spaced title", "Spaced title"], + ["> [!WARNING]+ heads up", "heads up"], + ["> [!WARNING]- heads up", "heads up"], + ["> [!TIP] **title**", "**title**"], + ]; + for (const [markerRow, title] of cases) { + it(`${JSON.stringify(markerRow)} hides up to the title`, () => { + const doc = `${markerRow}\n> body\n\npara`; + const state = stateFor(doc, doc.indexOf("para") + 1); + expect(calloutMarkerConceal(state.doc, state.selection, blockquotes(state)[0])).toEqual({ + from: 0, + to: doc.indexOf(title), + hidesLine: false, + }); + }); + } + + it("trailing whitespace alone is not a title: the whole row still hides", () => { + const doc = "> [!NOTE]+ \n> body\n\npara"; + const state = stateFor(doc, doc.indexOf("para") + 1); + expect(calloutMarkerConceal(state.doc, state.selection, blockquotes(state)[0])).toEqual({ + from: 0, + to: state.doc.line(1).to, + hidesLine: true, + }); + }); + + it("caret inside a titled callout reveals it (null)", () => { + const doc = "> [!NOTE] Title\n> body\n\npara"; + const state = stateFor(doc, doc.indexOf("body")); + expect(calloutMarkerConceal(state.doc, state.selection, blockquotes(state)[0])).toBeNull(); + }); +}); + describe("calloutMarkerConcealField — StateField", () => { // Settled: calloutMarkerConcealField.create() reads syntaxTree(state), so on a // truncated init snapshot the field is built over a partial tree and the assertions @@ -148,6 +191,25 @@ describe("calloutMarkerConcealField — StateField", () => { }); }); + it("a titled marker: one replace up to the title, no hidden line class, zone ≡ replace", () => { + for (const [markerRow, title] of [ + ["> [!WARNING] タイトル", "タイトル"], + [">[!NOTE] Title", "Title"], + [" > [!NOTE] Title", "Title"], + ["> [!WARNING]+ heads up", "heads up"], + ["> [!WARNING]- heads up", "heads up"], + ]) { + const doc = `${markerRow}\n> body\n\npara`; + const state = fieldState(doc, doc.indexOf("para") + 1); + const titleFrom = doc.indexOf(title); + const decos = dump(state.field(calloutMarkerConcealField).decorations); + expect(decos, markerRow).toEqual([{ from: 0, to: titleFrom, cls: undefined }]); + expect(state.facet(quollSyntaxExclusionZones), markerRow).toEqual([ + { from: 0, to: titleFrom }, + ]); + } + }); + it("caret INSIDE emits nothing and publishes no zone", () => { const doc = "> [!NOTE]\n> body\n\npara"; const state = fieldState(doc, 3); // caret in `[!NOTE]` @@ -204,11 +266,16 @@ describe("calloutMarkerConcealField — StateField", () => { parent, }); }).not.toThrow(); - // The field concealed the formatted-title marker row with a single replace. + // The field concealed only the marker (`> [!TIP] `) with a single replace; the + // formatted title stays on screen as the callout's title row. const v = view as unknown as EditorView; - const marker = v.state.doc.line(1); + const titleFrom = doc.indexOf("**title**"); const decos = dump(v.state.field(calloutMarkerConcealField).decorations); - expect(decos).toContainEqual({ from: marker.from, to: marker.to, cls: undefined }); + expect(decos).toEqual([{ from: 0, to: titleFrom, cls: undefined }]); + expect(v.state.facet(quollSyntaxExclusionZones)).toEqual([{ from: 0, to: titleFrom }]); + const titleRow = v.contentDOM.querySelector(".cm-line"); + expect(titleRow?.textContent).toContain("title"); + expect(titleRow?.textContent).not.toContain("[!TIP]"); v.destroy(); }); }); @@ -328,6 +395,14 @@ describe("calloutMarkerConcealField — bounded recompute ≡ full recompute", ( checkEquivalence(`${CALLOUT}\n\nafter`, [{ changes: { from: 2, to: 9, insert: "hello" } }]); }); + it("type a title onto the marker line, then delete it (span shrinks / regrows)", () => { + // `> [!NOTE]` is 9 bytes; typing ` Title` makes the row titled, deleting restores it. + checkEquivalence(`${CALLOUT}\n\nafter`, [ + { changes: { from: 9, insert: " Title" } }, + { changes: { from: 9, to: 15 } }, + ]); + }); + it("introduce a callout from scratch", () => { checkEquivalence("plain\n\nmore", [{ changes: { from: 0, to: 5, insert: CALLOUT } }]); }); From 0d982d2682684a2a176a9240189e1b287b2fcf4e Mon Sep 17 00:00:00 2001 From: Mitsuki Fukunaga Date: Fri, 4 Dec 2026 15:32:48 +1100 Subject: [PATCH 2/4] fix: keep an indented callout title aligned and treat any whitespace after the marker as untitled --- .../cm/decorations/callout-marker-conceal.ts | 51 +++++++++-------- src/webview/cm/decorations/callout.ts | 37 +++++++----- src/webview/cm/theme.ts | 5 +- src/webview/editor.ts | 10 ++-- .../callout-title-row.browser.test.ts | 13 +++++ ...-decoration-callout-marker-conceal.test.ts | 56 +++++++++++-------- 6 files changed, 107 insertions(+), 65 deletions(-) diff --git a/src/webview/cm/decorations/callout-marker-conceal.ts b/src/webview/cm/decorations/callout-marker-conceal.ts index e901456b..aaeab8b5 100644 --- a/src/webview/cm/decorations/callout-marker-conceal.ts +++ b/src/webview/cm/decorations/callout-marker-conceal.ts @@ -1,7 +1,7 @@ // StateField that CONCEALS the `[!TYPE]` marker of a callout when the caret is // OUTSIDE the whole callout block (mirrors fenced-code-collapse.ts's rebuild-on- -// selection template). The concealed span is `calloutConcealSpan` (callout.ts): from -// the marker line's start to where the title text starts. Per concealed marker it +// selection template). The concealed span is `calloutConcealSpan` (callout.ts): the +// whole first line when untitled, else from the first `>` to where the title starts. Per concealed marker it // emits ONE Decoration.replace({}) over that span and publishes the SAME span to // quollSyntaxExclusionZones, so: // - the orchestrator's arbitrate() drops EVERY inline reveal decoration overlapping @@ -42,13 +42,15 @@ type Zone = { from: number; to: number }; type Marker = Zone & { hidesLine: boolean }; /** Selection-INDEPENDENT facts about one outermost callout that HAS a body (a - * marker-only callout is never a record — it never conceals). `markerFrom` is - * both the block's first-line start AND the concealed marker span's start; - * [markerFrom, markerTo) + `hidesLine` are `calloutConcealSpan`'s result; - * `blockTo` is the block's last CONTENT line end (`doc.lineAt(node.to - 1).to`, + * marker-only callout is never a record — it never conceals). `blockFrom` is the + * block's first-line start (the reveal extent's start and the unique de-dup key); + * [markerFrom, markerTo) + `hidesLine` are `calloutConcealSpan`'s result (a titled + * indented row's `markerFrom` sits past the indent); `blockTo` is the block's last + * CONTENT line end (`doc.lineAt(node.to - 1).to`, * robust to a Lezer `to` overshoot per [[quoll-lezer-table-to-overshoots-trailing-line]]). * The selection-dependent conceal decision is applied later in `deriveMarkers`. */ interface CalloutRecord { + blockFrom: number; markerFrom: number; markerTo: number; hidesLine: boolean; @@ -56,7 +58,7 @@ interface CalloutRecord { } interface ConcealState { - /** Selection-independent, doc-ordered by `markerFrom`. The changed-range bounded + /** Selection-independent, doc-ordered by `blockFrom`. The changed-range bounded * recompute (Task 2) reuses/rebuilds THIS; markers/decorations/zones derive from it. */ records: readonly CalloutRecord[]; /** Concealed marker-line spans for the CURRENT selection, doc-ordered. Compared on @@ -74,7 +76,7 @@ interface ConcealState { * iterate materialises only the touched subtree — the whole point of the bounding * (PERF.md: the cost is whole-tree materialisation, NOT node descent, so this is * the changed-range shape, NOT a prune-descent). Doc order → already sorted by - * `markerFrom`. Selection-INDEPENDENT: the caret does not affect record membership. + * `blockFrom`. Selection-INDEPENDENT: the caret does not affect record membership. * `calloutTypeForOutermost` already excludes nested (`> >` inner) AND list-nested * (`- > [!NOTE]`) blockquotes (the marker regex anchors at `^ {0,3}>`), so no * container-descent special-casing is needed — a top-level callout is the only shape @@ -97,6 +99,7 @@ function buildRange(state: EditorState, rangeFrom: number, rangeTo: number): Cal return; } out.push({ + blockFrom: doc.lineAt(node.from).from, markerFrom: span.from, markerTo: span.to, hidesLine: span.hidesLine, @@ -125,37 +128,39 @@ function computeExtendedSpan(tr: Transaction): Interval[] { } /** Changed-range bounded record recompute: reuse every prior record whose FULL block - * extent [markerFrom, blockTo] is neither TOUCHED by the change nor intersecting the + * extent [blockFrom, blockTo] is neither TOUCHED by the change nor intersecting the * extendedSpan (position-mapped through `tr.changes`), and re-walk the tree only * INSIDE each span interval. Soundness: a callout's record can change only from * within its block (interior change → touched → re-walked, and the overlapping * Blockquote node — even one starting far above the span — is re-entered by the * bounded `iterate` and re-emitted with its true marker line) or from an adjacent - * line (G1 ±1 → intersects span → re-walked). De-dup by `markerFrom` (unique per + * line (G1 ±1 → intersects span → re-walked). De-dup by `blockFrom` (unique per * callout): a fresh walk over a span always wins over a reused mapping. */ function computeBoundedRecords( prev: readonly CalloutRecord[], tr: Transaction, intervals: Interval[] ): CalloutRecord[] { - const byMarker = new Map(); + const byBlock = new Map(); for (const rec of prev) { - const touched = tr.changes.touchesRange(rec.markerFrom, rec.blockTo) !== false; - const newFrom = tr.changes.mapPos(rec.markerFrom, 1); + const touched = tr.changes.touchesRange(rec.blockFrom, rec.blockTo) !== false; + const newFrom = tr.changes.mapPos(rec.blockFrom, 1); const newTo = tr.changes.mapPos(rec.blockTo, -1); if (!touched && !intersects(intervals, newFrom, newTo)) { - const markerTo = tr.changes.mapPos(rec.markerTo, -1); - if (newFrom === rec.markerFrom && markerTo === rec.markerTo && newTo === rec.blockTo) { + // Untouched: the marker span moves rigidly with the block start. + const shift = newFrom - rec.blockFrom; + if (shift === 0 && newTo === rec.blockTo) { // Zero-shift reuse: return the SAME object (block structure unchanged AND // positions unmoved — an edit strictly BELOW the record). Object identity is // the non-vacuity anchor the reuse test asserts (mirrors imageBlockField // reusing the exact deco on a no-shift). - byMarker.set(rec.markerFrom, rec); + byBlock.set(rec.blockFrom, rec); } else { // Position shift only: block structure unchanged (untouched + outside span). - byMarker.set(newFrom, { - markerFrom: newFrom, - markerTo, + byBlock.set(newFrom, { + blockFrom: newFrom, + markerFrom: rec.markerFrom + shift, + markerTo: rec.markerTo + shift, hidesLine: rec.hidesLine, blockTo: newTo, }); @@ -164,21 +169,21 @@ function computeBoundedRecords( } for (const iv of intervals) { for (const rec of buildRange(tr.state, iv.from, iv.to)) { - byMarker.set(rec.markerFrom, rec); // fresh wins (a callout spanning two intervals de-dupes) + byBlock.set(rec.blockFrom, rec); // fresh wins (a callout spanning two intervals de-dupes) } } - return [...byMarker.values()].sort((a, b) => a.markerFrom - b.markerFrom); + return [...byBlock.values()].sort((a, b) => a.blockFrom - b.blockFrom); } /** Apply the SELECTION-dependent conceal decision to a record list. A callout's * marker row conceals iff no selection range intersects its full block span - * [markerFrom, blockTo] — identical to `calloutBlockRevealed` / `calloutMarkerConceal` + * [blockFrom, blockTo] — identical to `calloutBlockRevealed` / `calloutMarkerConceal` * in callout.ts (the marker-only + not-a-callout cases are already excluded at * record-build time). Records are doc-ordered, so markers come out doc-ordered. */ function deriveMarkers(records: readonly CalloutRecord[], state: EditorState): Marker[] { const markers: Marker[] = []; for (const rec of records) { - if (!intersectsAnySelection(state.selection, rec.markerFrom, rec.blockTo)) { + if (!intersectsAnySelection(state.selection, rec.blockFrom, rec.blockTo)) { markers.push({ from: rec.markerFrom, to: rec.markerTo, hidesLine: rec.hidesLine }); } } diff --git a/src/webview/cm/decorations/callout.ts b/src/webview/cm/decorations/callout.ts index 8770e895..a6c41b7d 100644 --- a/src/webview/cm/decorations/callout.ts +++ b/src/webview/cm/decorations/callout.ts @@ -85,10 +85,13 @@ export function calloutTypeForLine(lineText: string): CalloutType | null { } /** The `[!TYPE]` match of a blockquote first line (see `calloutTypeForLine` for the - * prefix grammar), with `markerEnd` = the offset in `lineText` just past the - * marker, its optional fold suffix and any spaces/tabs after it — i.e. where the - * title text starts (`lineText.length` when there is no title). */ -function matchCalloutMarker(lineText: string): { type: CalloutType; markerEnd: number } | null { + * prefix grammar), with `quoteStart` = the offset of the first `>` (past the 0-3 + * spaces of initial indent) and `markerEnd` = the offset just past the marker, its + * optional fold suffix and the whitespace after it — i.e. where the title text + * starts (`lineText.length` when there is no title). */ +function matchCalloutMarker( + lineText: string +): { type: CalloutType; quoteStart: number; markerEnd: number } | null { let i = 0; let column = 0; // Up to 3 spaces of initial indent (spaces only; a leading tab reaches column 4 @@ -99,6 +102,7 @@ function matchCalloutMarker(lineText: string): { type: CalloutType; markerEnd: n if (lineText[i] !== ">") { return null; } + const quoteStart = i; let contentIndent = 0; for (;;) { i += 1; // consume the `>` marker @@ -124,11 +128,13 @@ function matchCalloutMarker(lineText: string): { type: CalloutType; markerEnd: n if (m === null) { return null; } + // Skip the same whitespace class the marker's `(?=\s|$)` lookahead accepts, so a + // marker followed only by e.g. a no-break space is untitled, not a blank title. let markerEnd = i + m[0].length; - while (lineText[markerEnd] === " " || lineText[markerEnd] === "\t") { + while (markerEnd < lineText.length && /\s/.test(lineText[markerEnd])) { markerEnd += 1; } - return { type: m[1].toLowerCase() as CalloutType, markerEnd }; + return { type: m[1].toLowerCase() as CalloutType, quoteStart, markerEnd }; } /** True when `node` sits inside another Blockquote (a nested `> >` inner node). @@ -169,12 +175,14 @@ export function calloutBlockRevealed( return intersectsAnySelection(selection, doc.lineAt(node.from).from, doc.lineAt(node.to - 1).to); } -/** The span a callout conceals while the caret is outside it: `{from, to}` from the - * marker line's start to where the title text starts (past the `[!TYPE]` match, its - * optional `+`/`-` fold suffix and the whitespace after it), plus `hidesLine` — true - * when nothing but whitespace follows the marker, so the whole row is hidden and - * collapses to zero height; false when a title follows and the row stays visible as - * the callout's title row. null when `node` is not an outermost callout, or the +/** The span a callout conceals while the caret is outside it, plus `hidesLine`. + * Untitled (nothing but whitespace after the marker): `hidesLine` is true and the + * span is the whole first line, which collapses to zero height. Titled: `hidesLine` + * is false and the span runs from the first `>` to where the title text starts (past + * the `[!TYPE]` match, its optional `+`/`-` fold suffix and the whitespace after it); + * the row stays visible as the callout's title row. The 0-3 spaces of indent before + * `>` stay visible, exactly as blockquote-reveal leaves them on the body rows, so the + * title lines up with the body. null when `node` is not an outermost callout, or the * callout is marker-ONLY (no body line — concealing would leave nothing to show). * Selection-INDEPENDENT; the ONE computation the conceal StateField's replace, its * exclusion zone and block-style's corner migration all derive from. */ @@ -190,10 +198,11 @@ export function calloutConcealSpan( if (match === null || doc.lineAt(node.to - 1).number === firstLine.number) { return null; // not a callout, or marker-only: NEVER conceal a bodyless callout } + const hidesLine = match.markerEnd === firstLine.length; return { - from: firstLine.from, + from: hidesLine ? firstLine.from : firstLine.from + match.quoteStart, to: firstLine.from + match.markerEnd, - hidesLine: match.markerEnd === firstLine.length, + hidesLine, }; } diff --git a/src/webview/cm/theme.ts b/src/webview/cm/theme.ts index bea19775..506826d0 100644 --- a/src/webview/cm/theme.ts +++ b/src/webview/cm/theme.ts @@ -670,8 +670,9 @@ export const blockStyleThemeSpec = { }, // Callout admonitions (classification in decorations/callout.ts). An OUTERMOST // blockquote whose first line is `[!TYPE]` carries `quoll-callout - // quoll-callout-{type}` on every line (+ `quoll-callout-marker` on the REVEALED - // marker row; the row is concealed when the caret is outside the block). + // quoll-callout-{type}` on every line (+ `quoll-callout-marker` on the marker row + // whenever it is visible: revealed, or a titled row concealed down to its title; an + // untitled marker row is hidden whole when the caret is outside the block). // The callout reuses the blockquote panel WHOLESALE — the plain shared // --quoll-surface-fill background and the body-column alignment (the transparent // 6px/2px border + `background-clip: padding-box`, both inherited from diff --git a/src/webview/editor.ts b/src/webview/editor.ts index c40e897b..d15d5a38 100644 --- a/src/webview/editor.ts +++ b/src/webview/editor.ts @@ -830,10 +830,12 @@ export function mountEditor(opts: EditorOptions): EditorHandle { // (no-boundary-fence) case. Both emit Decoration.line; CodeMirror unions // their classes on a shared `> ```…` ` line. Styled by quollBlockStyleTheme above. blockStyle, - // Caret-outside conceal of the [!TYPE] marker row; publishes its span to - // quollSyntaxExclusionZones (block-style then migrates the -open corner - // onto the first visible body line, and the orchestrator drops inline - // marks on the row). Block widgets MUST come from a StateField. + // Caret-outside conceal of the [!TYPE] marker (the whole row when untitled, + // `>` up to the title when titled); publishes that span to + // quollSyntaxExclusionZones (block-style migrates the -open corner onto the + // first visible body line only for a hidden untitled row, and the + // orchestrator drops inline marks overlapping the span). Block widgets MUST + // come from a StateField. calloutMarkerConcealField, // Copy-code button: a selection-independent ViewPlugin emitting one // inline point widget at each visible fenced block's open line — top-level diff --git a/test/webview-browser/callout-title-row.browser.test.ts b/test/webview-browser/callout-title-row.browser.test.ts index a775a8fa..8da8849a 100644 --- a/test/webview-browser/callout-title-row.browser.test.ts +++ b/test/webview-browser/callout-title-row.browser.test.ts @@ -110,6 +110,19 @@ describe("callout title row — painted corners and padding (real Chromium)", () }); } + it("an indented titled callout: the title lines up with the body text", async () => { + // Body rows keep the 0-3 spaces of indent before `>` (blockquote-reveal hides only + // the `>`), so the title row must keep them too. + const doc = " > [!NOTE] Title\n > body\n\npara"; + view = mount(doc, doc.indexOf("para") + 1); + await settled(); + const left = (pos: number): number => (view as EditorView).coordsAtPos(pos)?.left ?? Number.NaN; + expect(rowFacts(view).text).toContain("Title"); + expect(Math.abs(left(doc.indexOf("Title")) - left(doc.indexOf("body")))).toBeLessThanOrEqual( + 0.5 + ); + }); + it("contrast: an untitled callout still hides its marker row and the body takes the corner", async () => { const doc = "> [!WARNING]\n> body\n\npara"; view = mount(doc, doc.indexOf("para") + 1); diff --git a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts index 0fa123ed..16e7fe9c 100644 --- a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts +++ b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts @@ -117,7 +117,8 @@ describe("calloutMarkerConceal — pure predicate", () => { describe("calloutMarkerConceal — a titled marker hides only the marker", () => { // REV-20261203-15: the title text after `[!TYPE]` (and its optional fold suffix) is - // the callout's title row, so caret-outside hides [line start, title start) only. + // the callout's title row, so caret-outside hides [first `>`, title start) only. Any + // 0-3 spaces of indent before `>` stay, as they do on the body rows. const cases: Array<[string, string]> = [ ["> [!WARNING] タイトル", "タイトル"], [">[!NOTE] Title", "Title"], @@ -126,28 +127,31 @@ describe("calloutMarkerConceal — a titled marker hides only the marker", () => ["> [!WARNING]+ heads up", "heads up"], ["> [!WARNING]- heads up", "heads up"], ["> [!TIP] **title**", "**title**"], + ["> [!NOTE]\u00a0Title", "Title"], ]; for (const [markerRow, title] of cases) { - it(`${JSON.stringify(markerRow)} hides up to the title`, () => { + it(`${JSON.stringify(markerRow)} hides from the first \`>\` up to the title`, () => { const doc = `${markerRow}\n> body\n\npara`; const state = stateFor(doc, doc.indexOf("para") + 1); expect(calloutMarkerConceal(state.doc, state.selection, blockquotes(state)[0])).toEqual({ - from: 0, + from: markerRow.indexOf(">"), to: doc.indexOf(title), hidesLine: false, }); }); } - it("trailing whitespace alone is not a title: the whole row still hides", () => { - const doc = "> [!NOTE]+ \n> body\n\npara"; - const state = stateFor(doc, doc.indexOf("para") + 1); - expect(calloutMarkerConceal(state.doc, state.selection, blockquotes(state)[0])).toEqual({ - from: 0, - to: state.doc.line(1).to, - hidesLine: true, + for (const markerRow of ["> [!NOTE]+ ", "> [!NOTE]\u00a0", " > [!NOTE]"]) { + it(`${JSON.stringify(markerRow)} has no title: the whole row still hides`, () => { + const doc = `${markerRow}\n> body\n\npara`; + const state = stateFor(doc, doc.indexOf("para") + 1); + expect(calloutMarkerConceal(state.doc, state.selection, blockquotes(state)[0])).toEqual({ + from: 0, + to: state.doc.line(1).to, + hidesLine: true, + }); }); - }); + } it("caret inside a titled callout reveals it (null)", () => { const doc = "> [!NOTE] Title\n> body\n\npara"; @@ -201,12 +205,11 @@ describe("calloutMarkerConcealField — StateField", () => { ]) { const doc = `${markerRow}\n> body\n\npara`; const state = fieldState(doc, doc.indexOf("para") + 1); + const from = markerRow.indexOf(">"); const titleFrom = doc.indexOf(title); const decos = dump(state.field(calloutMarkerConcealField).decorations); - expect(decos, markerRow).toEqual([{ from: 0, to: titleFrom, cls: undefined }]); - expect(state.facet(quollSyntaxExclusionZones), markerRow).toEqual([ - { from: 0, to: titleFrom }, - ]); + expect(decos, markerRow).toEqual([{ from, to: titleFrom, cls: undefined }]); + expect(state.facet(quollSyntaxExclusionZones), markerRow).toEqual([{ from, to: titleFrom }]); } }); @@ -239,8 +242,9 @@ describe("calloutMarkerConcealField — StateField", () => { // Crash regression (v2 Finding 2): a marker line with inline markup // (`> [!TIP] **title**`) would, under an inline-provider design, leave two // overlapping Decoration.replace on the line (the `>` hide + the `**` hide) and - // CodeMirror throws. The StateField owns the WHOLE line as ONE replace + publishes - // its span, so quollSyntaxReveal's inline marks are arbitrated away — mounting the + // CodeMirror throws. The StateField owns `>` + marker as ONE replace and publishes + // exactly that span, so any inline reveal overlapping it is arbitrated away while + // the title's own `**` hides (which start at the span end) survive — mounting the // full stack must NOT throw. it("mounts `> [!TIP] **title**` with the full reveal stack without throwing", () => { const doc = "> [!TIP] **title**\n> body\n\npara"; @@ -395,11 +399,19 @@ describe("calloutMarkerConcealField — bounded recompute ≡ full recompute", ( checkEquivalence(`${CALLOUT}\n\nafter`, [{ changes: { from: 2, to: 9, insert: "hello" } }]); }); - it("type a title onto the marker line, then delete it (span shrinks / regrows)", () => { - // `> [!NOTE]` is 9 bytes; typing ` Title` makes the row titled, deleting restores it. - checkEquivalence(`${CALLOUT}\n\nafter`, [ - { changes: { from: 9, insert: " Title" } }, - { changes: { from: 9, to: 15 } }, + // `> [!NOTE]` is 9 bytes. One edit per case so the oracle compares the state with + // the title present (typing) and the state with it gone (deleting). + it("type a title onto an untitled marker line (whole-row span → title span)", () => { + checkEquivalence(`${CALLOUT}\n\nafter`, [{ changes: { from: 9, insert: " Title" } }]); + }); + + it("delete a titled marker's title (title span → whole-row span)", () => { + checkEquivalence("> [!NOTE] Title\n> body\n\nafter", [{ changes: { from: 9, to: 15 } }]); + }); + + it("an edit above an indented titled callout shifts its marker span rigidly", () => { + checkEquivalence("para\n\n > [!NOTE] Title\n > body", [ + { changes: { from: 0, insert: "more " } }, ]); }); From 706c26ddb0c132de35147c2d6849c56377850e45 Mon Sep 17 00:00:00 2001 From: Mitsuki Fukunaga Date: Fri, 4 Dec 2026 15:41:09 +1100 Subject: [PATCH 3/4] test: pin that the indented-callout shift case takes the bounded path --- .../cm-decoration-callout-marker-conceal.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts index 16e7fe9c..b0a2ff6d 100644 --- a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts +++ b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts @@ -11,6 +11,7 @@ import { import { calloutMarkerConcealField } from "../../../src/webview/cm/decorations/callout-marker-conceal.js"; import { quollSyntaxReveal } from "../../../src/webview/cm/decorations/index.js"; import { quollSyntaxExclusionZones } from "../../../src/webview/cm/decorations/orchestrator.js"; +import { touchesStructuralReparse } from "../../../src/webview/cm/structural-guard.js"; import { fullTree } from "../helpers/full-tree.js"; import { settledState } from "../helpers/settled-state.js"; import { settledMount } from "../helpers/settled-view.js"; @@ -400,7 +401,10 @@ describe("calloutMarkerConcealField — bounded recompute ≡ full recompute", ( }); // `> [!NOTE]` is 9 bytes. One edit per case so the oracle compares the state with - // the title present (typing) and the state with it gone (deleting). + // the title present (typing) and the state with it gone (deleting). Both edits touch + // a `>` line, which `touchesStructuralReparse` treats as structural, so they pin the + // full-rebuild arm's title-span transitions, NOT computeBoundedRecords (the rigid + // shift case below is the bounded one). it("type a title onto an untitled marker line (whole-row span → title span)", () => { checkEquivalence(`${CALLOUT}\n\nafter`, [{ changes: { from: 9, insert: " Title" } }]); }); @@ -410,9 +414,12 @@ describe("calloutMarkerConcealField — bounded recompute ≡ full recompute", ( }); it("an edit above an indented titled callout shifts its marker span rigidly", () => { - checkEquivalence("para\n\n > [!NOTE] Title\n > body", [ - { changes: { from: 0, insert: "more " } }, - ]); + const doc = "para\n\n > [!NOTE] Title\n > body"; + const edit = { changes: { from: 0, insert: "more " } }; + // Non-vacuity: this edit is NOT structural, and checkEquivalence rules out a + // starved frontier, so the live field takes computeBoundedRecords' rigid-shift arm. + expect(touchesStructuralReparse(stateFor(doc, 0).update(edit))).toBe(false); + checkEquivalence(doc, [edit]); }); it("introduce a callout from scratch", () => { From ccc1a652b39d97c09ca58504747cb7b354e17132 Mon Sep 17 00:00:00 2001 From: Mitsuki Fukunaga Date: Fri, 4 Dec 2026 15:45:46 +1100 Subject: [PATCH 4/4] test: run the field conceal assertions over every titled-marker spelling --- ...-decoration-callout-marker-conceal.test.ts | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts index b0a2ff6d..23ce5275 100644 --- a/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts +++ b/test/webview/decorations/cm-decoration-callout-marker-conceal.test.ts @@ -116,21 +116,26 @@ describe("calloutMarkerConceal — pure predicate", () => { }); }); +/** Titled marker rows and their title text — shared by the predicate and field + * tests so both cover every spelling (indent, no space after `>`, tab, fold + * suffixes, inline markup, a no-break space before the title). */ +const TITLED_MARKERS: ReadonlyArray<[string, string]> = [ + ["> [!WARNING] タイトル", "タイトル"], + [">[!NOTE] Title", "Title"], + [" > [!NOTE] Title", "Title"], + [" > [!NOTE] Title", "Title"], + [">\t[!TIP] Spaced title", "Spaced title"], + ["> [!WARNING]+ heads up", "heads up"], + ["> [!WARNING]- heads up", "heads up"], + ["> [!TIP] **title**", "**title**"], + ["> [!NOTE]\u00a0Title", "Title"], +]; + describe("calloutMarkerConceal — a titled marker hides only the marker", () => { // REV-20261203-15: the title text after `[!TYPE]` (and its optional fold suffix) is // the callout's title row, so caret-outside hides [first `>`, title start) only. Any // 0-3 spaces of indent before `>` stay, as they do on the body rows. - const cases: Array<[string, string]> = [ - ["> [!WARNING] タイトル", "タイトル"], - [">[!NOTE] Title", "Title"], - [" > [!NOTE] Title", "Title"], - [">\t[!TIP] Spaced title", "Spaced title"], - ["> [!WARNING]+ heads up", "heads up"], - ["> [!WARNING]- heads up", "heads up"], - ["> [!TIP] **title**", "**title**"], - ["> [!NOTE]\u00a0Title", "Title"], - ]; - for (const [markerRow, title] of cases) { + for (const [markerRow, title] of TITLED_MARKERS) { it(`${JSON.stringify(markerRow)} hides from the first \`>\` up to the title`, () => { const doc = `${markerRow}\n> body\n\npara`; const state = stateFor(doc, doc.indexOf("para") + 1); @@ -197,13 +202,7 @@ describe("calloutMarkerConcealField — StateField", () => { }); it("a titled marker: one replace up to the title, no hidden line class, zone ≡ replace", () => { - for (const [markerRow, title] of [ - ["> [!WARNING] タイトル", "タイトル"], - [">[!NOTE] Title", "Title"], - [" > [!NOTE] Title", "Title"], - ["> [!WARNING]+ heads up", "heads up"], - ["> [!WARNING]- heads up", "heads up"], - ]) { + for (const [markerRow, title] of TITLED_MARKERS) { const doc = `${markerRow}\n> body\n\npara`; const state = fieldState(doc, doc.indexOf("para") + 1); const from = markerRow.indexOf(">");