Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(md): keep the outline rail out of the checkbox gutter (#7661)

Peter Chinman148c976df2c3
diff --git a/apps/web/src/features/block-md/component/MarkdownOutline.test.ts b/apps/web/src/features/block-md/component/MarkdownOutline.test.ts
index 9067135d1d..a99f9c188d 100644
--- a/apps/web/src/features/block-md/component/MarkdownOutline.test.ts
+++ b/apps/web/src/features/block-md/component/MarkdownOutline.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest';
-import { getVisibleHeadingIndexes, shouldShowOutline } from './MarkdownOutline';
+import {
+ getVisibleHeadingIndexes,
+ MARKDOWN_OUTLINE_INSET,
+ MARKDOWN_OUTLINE_WIDTH,
+ outlineFitsGutter,
+ shouldShowOutline,
+} from './MarkdownOutline';
describe('getVisibleHeadingIndexes', () => {
it('highlights every section overlapping the viewport', () => {
@@ -49,3 +55,22 @@ describe('shouldShowOutline', () => {
expect(shouldShowOutline(3, true)).toBe(true);
});
});
+
+describe('outlineFitsGutter', () => {
+ const fits = MARKDOWN_OUTLINE_INSET + MARKDOWN_OUTLINE_WIDTH;
+
+ it('needs the whole rail to sit left of the text column', () => {
+ expect(outlineFitsGutter(fits)).toBe(true);
+ expect(outlineFitsGutter(fits - 1)).toBe(false);
+ });
+
+ it('rejects the gutters comment layouts leave for the text column', () => {
+ // CommentLayoutMode.md and .xs pin the column to the container padding.
+ expect(outlineFitsGutter(32)).toBe(false);
+ expect(outlineFitsGutter(24)).toBe(false);
+ });
+
+ it('is unmeasured until the notebook has laid out', () => {
+ expect(outlineFitsGutter(0)).toBe(false);
+ });
+});
diff --git a/apps/web/src/features/block-md/component/MarkdownOutline.tsx b/apps/web/src/features/block-md/component/MarkdownOutline.tsx
index 1c9698efe9..2c060734b6 100644
--- a/apps/web/src/features/block-md/component/MarkdownOutline.tsx
+++ b/apps/web/src/features/block-md/component/MarkdownOutline.tsx
@@ -21,6 +21,7 @@ const HEADING_SCROLL_OFFSET = 80;
const SECTION_PREVIEW_LENGTH = 240;
const MIN_OUTLINE_HEADINGS = 3;
export const MARKDOWN_OUTLINE_WIDTH = 40;
+export const MARKDOWN_OUTLINE_INSET = 16;
export function shouldShowOutline(
headingCount: number,
@@ -29,6 +30,20 @@ export function shouldShowOutline(
return enabled && headingCount >= MIN_OUTLINE_HEADINGS;
}
+/**
+ * Whether the rail fits in the margin left of the text column, given that
+ * column's own distance from the notebook's left edge. The rail takes pointer
+ * events, so fitting the notebook is not enough: checkbox markers are
+ * `li::before` boxes drawn outside the list item and flush with the column's
+ * left edge, and a rail reaching past the column swallows the click that would
+ * tick one. The margin has to be measured rather than derived from the
+ * notebook's width, because a comment layout pushes the column left without
+ * making the notebook any narrower.
+ */
+export function outlineFitsGutter(contentInset: number): boolean {
+ return contentInset >= MARKDOWN_OUTLINE_INSET + MARKDOWN_OUTLINE_WIDTH;
+}
+
/** A section runs from its heading to the next heading (or the editor end). */
export function getVisibleHeadingIndexes(
headingTops: number[],
@@ -278,6 +293,10 @@ export function MarkdownOutline(props: {
}
contentZIndexClass="z-item-options-menu"
gutter={10}
+ // The preview covers the text column's left edge, including the
+ // checkbox markers, so it must not take the pointer that is on
+ // its way to one.
+ passThroughPointerEvents
placement="right"
portalMount={props.portalMount()}
trigger={
diff --git a/apps/web/src/features/block-md/component/Notebook.tsx b/apps/web/src/features/block-md/component/Notebook.tsx
index 732686e467..a3ed723d60 100644
--- a/apps/web/src/features/block-md/component/Notebook.tsx
+++ b/apps/web/src/features/block-md/component/Notebook.tsx
@@ -39,8 +39,10 @@ import { InstructionsEditor } from './InstructionsEditor';
import { MarkdownEditor } from './MarkdownEditor';
import { useMarkdownName } from './MarkdownNameProvider';
import {
+ MARKDOWN_OUTLINE_INSET,
MARKDOWN_OUTLINE_WIDTH,
MarkdownOutline,
+ outlineFitsGutter,
useMarkdownOutline,
} from './MarkdownOutline';
import { TaskDuplicateMatchPill } from './TaskDuplicateMatches';
@@ -64,9 +66,6 @@ const NoteTargetWidth = 768;
const CommentTargetWidth = 320;
const GapTargetWidth = 24;
const MinimizedCommentTargetWidth = 48;
-const OutlineEdgeInset = 16;
-const OutlineMinWidth =
- NoteTargetWidth + 2 * (MARKDOWN_OUTLINE_WIDTH + OutlineEdgeInset);
enum CommentLayoutMode {
lg = 'lg',
@@ -115,11 +114,12 @@ export function Notebook(props: {
const [width, setWidth] = createSignal<number>();
const [leftFloatX, setLeftFloatX] = createSignal(0);
+ const [contentInset, setContentInset] = createSignal(0);
const commentBreakpoints = createSizeBreakpoints(width, CommentBreakpoints);
const canUseLexicalStateDebugger = useCanUseLexicalStateDebugger();
const outline = useMarkdownOutline({
editor: () => md.editor,
- enabled: () => (width() ?? 0) >= OutlineMinWidth && !isMobile(),
+ enabled: () => outlineFitsGutter(contentInset()) && !isMobile(),
});
const hasComment = createMemo(() => {
@@ -187,13 +187,17 @@ export function Notebook(props: {
const observeCallback = () => {
const { width, left } = notebookRef.getBoundingClientRect();
setWidth(width);
- const leftFloat =
- contentRef.getBoundingClientRect().right - left + GapTargetWidth;
- setLeftFloatX(leftFloat);
+ const content = contentRef.getBoundingClientRect();
+ setContentInset(content.left - left);
+ setLeftFloatX(content.right - left + GapTargetWidth);
};
const { observe } = makeResizeObserver(observeCallback);
observeCallback();
observe(notebookRef);
+ // A comment layout change resizes the text column without resizing the
+ // notebook, and it is the column's own geometry the outline is placed
+ // against.
+ observe(contentRef);
});
createEffect(() => {
@@ -331,7 +335,7 @@ export function Notebook(props: {
<div
class="pointer-events-none absolute inset-y-0 z-1"
style={{
- left: `${OutlineEdgeInset}px`,
+ left: `${MARKDOWN_OUTLINE_INSET}px`,
width: `${MARKDOWN_OUTLINE_WIDTH}px`,
}}
>
diff --git a/apps/web/src/lib/core/component/HoverCard.test.tsx b/apps/web/src/lib/core/component/HoverCard.test.tsx
index bea2b830f9..d10f582c81 100644
--- a/apps/web/src/lib/core/component/HoverCard.test.tsx
+++ b/apps/web/src/lib/core/component/HoverCard.test.tsx
@@ -12,7 +12,8 @@ vi.mock('@core/mobile/isTouchDevice', () => ({
async function renderOpenCard(
keepOpenOnTriggerPress?: boolean,
- closeOnScroll?: boolean
+ closeOnScroll?: boolean,
+ passThroughPointerEvents?: boolean
) {
const onOpenChange = vi.fn();
render(() => (
@@ -22,6 +23,7 @@ async function renderOpenCard(
onOpenChange={onOpenChange}
keepOpenOnTriggerPress={keepOpenOnTriggerPress}
closeOnScroll={closeOnScroll}
+ passThroughPointerEvents={passThroughPointerEvents}
trigger={<span>Standup</span>}
content={<div>Card</div>}
/>
@@ -78,4 +80,26 @@ describe('HoverCard', () => {
fireEvent.pointerDown(screen.getByText('Elsewhere'));
expect(onOpenChange).toHaveBeenCalledWith(false);
});
+
+ it('takes the pointer by default', async () => {
+ await renderOpenCard();
+
+ const content = screen.getByText('Card').parentElement;
+ expect(content?.className).not.toContain('pointer-events-none');
+ expect(
+ content?.closest<HTMLElement>('[data-popper-positioner]')?.style
+ .pointerEvents
+ ).toBe('');
+ });
+
+ it('lets the pointer through the card and its positioner when asked', async () => {
+ await renderOpenCard(undefined, undefined, true);
+
+ const content = screen.getByText('Card').parentElement;
+ expect(content?.className).toContain('pointer-events-none!');
+ expect(
+ content?.closest<HTMLElement>('[data-popper-positioner]')?.style
+ .pointerEvents
+ ).toBe('none');
+ });
});
diff --git a/apps/web/src/lib/core/component/HoverCard.tsx b/apps/web/src/lib/core/component/HoverCard.tsx
index 2551b9ca0d..45e874cd8e 100644
--- a/apps/web/src/lib/core/component/HoverCard.tsx
+++ b/apps/web/src/lib/core/component/HoverCard.tsx
@@ -122,6 +122,13 @@ export type HoverCardComponentProps = {
keepOpenOnTriggerPress?: boolean;
/** Dismiss on outside scrolling (default: true). Disable for stationary triggers. */
closeOnScroll?: boolean;
+ /**
+ * Let pointer events reach whatever the card overlays. Use for a purely
+ * informational card that covers interactive content: without it the card
+ * holds itself open under the pointer and swallows clicks meant for the
+ * surface below.
+ */
+ passThroughPointerEvents?: boolean;
/** Callback when open state changes */
onOpenChange?: (open: boolean) => void;
/**
@@ -153,7 +160,7 @@ export function HoverCard(props: HoverCardComponentProps) {
const [nestedOpenCount, setNestedOpenCount] = createSignal(0);
const [isHoverCardOpen, setIsHoverCardOpen] = createSignal(false);
- let contentEl: HTMLElement | undefined;
+ const [contentEl, setContentEl] = createSignal<HTMLElement>();
let entry: HoverCardEntry;
@@ -311,7 +318,7 @@ export function HoverCard(props: HoverCardComponentProps) {
const onScroll = (e: Event) => {
const target = e.target;
- if (target instanceof Node && contentEl?.contains(target)) return;
+ if (target instanceof Node && contentEl()?.contains(target)) return;
handleOpenChange(false);
};
@@ -324,6 +331,19 @@ export function HoverCard(props: HoverCardComponentProps) {
});
});
+ // Kobalte positions the card inside a wrapper element of its own, so opting
+ // the content out of hit testing is not enough: the wrapper is the same size
+ // and still takes the pointer.
+ createEffect(() => {
+ if (!props.passThroughPointerEvents) return;
+ const positioner = contentEl()?.closest<HTMLElement>(
+ '[data-popper-positioner]'
+ );
+ if (!positioner) return;
+ positioner.style.pointerEvents = 'none';
+ onCleanup(() => positioner.style.removeProperty('pointer-events'));
+ });
+
// Kobalte forwards these to the content's DismissableLayer but leaves them
// out of the hover-card content types.
const dismissableLayerProps = {
@@ -374,12 +394,15 @@ export function HoverCard(props: HoverCardComponentProps) {
<KobalteHoverCard.Portal mount={props.portalMount}>
<KobalteHoverCard.Content
ref={(el) => {
- contentEl = el;
+ setContentEl(el);
props.contentRef?.(el);
}}
{...dismissableLayerProps}
class={cn(
props.contentZIndexClass ?? 'z-tool-tip',
+ // `!` because the dismissable layer writes `pointer-events: auto`
+ // onto this element.
+ props.passThroughPointerEvents && 'pointer-events-none!',
props.contentClass
)}
>
diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.md
index efa638990b..c80db1c86d 100644
--- a/docs/AGENT_GUIDE/documents.md
+++ b/docs/AGENT_GUIDE/documents.md
@@ -55,12 +55,19 @@ An empty title uses **New Note** when expanding.
## Markdown outline
On desktop, Markdown documents with at least three headings show a tick rail in
-the left margin. Every section whose content overlaps the editor viewport is
+the left margin. The rail appears only where the text column's left margin is
+wide enough to hold it clear of the text, so it never overlaps the checkbox
+markers of a checklist; a document whose margin comments have pushed the text
+column against the container padding shows no rail at any window width. Every
+section whose content overlaps the editor viewport is
highlighted, including a section whose heading has already scrolled above it.
Hover a tick (or Tab to its button) to expand it and nearby ticks and show a
rounded preview with the section heading and up to three lines of body text.
While a preview is open, only its tick is emphasized; visible-section highlights
return when the preview closes.
+The preview overlays the text column, but it does not take the pointer: a click
+that lands on it reaches the document underneath, so checkboxes it covers still
+toggle, and moving off the rail closes it even if the pointer crosses the card.
Click a tick or press Enter to jump immediately to its heading without closing its preview
or collapsing the expanded ticks. Scrolling, resizing, and
editor updates refresh the visible-section highlights.