Skip to content

Commit 3ab292a

Browse files
committed
Move attribution toggle from YAML metadata to Settings sidebar
Attribution was previously opt-in via `attribution: true` in the qmd YAML frontmatter. This is a viewing concern, not a document property, so move it to a persistent UI toggle in the Settings sidebar instead. The toggle appears only when the preview format is q2-debug and is labeled "Authorship" for clarity. The preference persists across sessions via localStorage.
1 parent 0f08bce commit 3ab292a

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

hub-client/src/components/Editor.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useCallback, useRef, useEffect, useMemo } from 'react';
1+
import { useState, useCallback, useRef, useEffect } from 'react';
22
import MonacoEditor from '@monaco-editor/react';
33
import type * as Monaco from 'monaco-editor';
44
import type { ProjectEntry, FileEntry } from '../types/project';
@@ -360,19 +360,9 @@ export default function Editor({ project, files, fileContents, onDisconnect, onC
360360
// effect's setContent(automergeContent) always produces a state change.
361361
const displayContent = replayState.isActive ? replayState.currentContent : content;
362362

363-
// Per-node attribution for q2-debug AST view (opt-in via `attribution: true` in YAML metadata)
364-
const attributionEnabled = useMemo(() => {
365-
if (currentFormat !== 'q2-debug' || !astJson) return false;
366-
try {
367-
const ast = JSON.parse(astJson);
368-
const val = ast?.meta?.attribution;
369-
// MetaBool: { t: "MetaBool", c: true }
370-
if (val?.t === 'MetaBool') return val.c === true;
371-
// MetaString: { t: "MetaString", c: "true" }
372-
if (val?.t === 'MetaString') return val.c === 'true';
373-
return false;
374-
} catch { return false; }
375-
}, [currentFormat, astJson]);
363+
// Per-node attribution for q2-debug AST view (opt-in via Settings sidebar toggle)
364+
const [attributionPref, setAttributionPref] = usePreference('attributionEnabled');
365+
const attributionEnabled = currentFormat === 'q2-debug' && attributionPref;
376366
const attribution = useAttribution(attributionEnabled ? (currentFile?.path ?? null) : null, displayContent);
377367
const attributionContextValue = attribution ? {
378368
attributionMap: attribution.attributionMap,
@@ -986,6 +976,9 @@ export default function Editor({ project, files, fileContents, onDisconnect, onC
986976
<SettingsTab
987977
scrollSyncEnabled={scrollSyncEnabled}
988978
onScrollSyncChange={setScrollSyncEnabled}
979+
attributionEnabled={attributionPref}
980+
onAttributionChange={setAttributionPref}
981+
currentFormat={currentFormat ?? ''}
989982
/>
990983
);
991984
case 'about':

hub-client/src/components/tabs/SettingsTab.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ import { usePreference } from '../../hooks/usePreference';
1515
interface SettingsTabProps {
1616
scrollSyncEnabled: boolean;
1717
onScrollSyncChange: (enabled: boolean) => void;
18+
attributionEnabled: boolean;
19+
onAttributionChange: (enabled: boolean) => void;
20+
currentFormat: string;
1821
}
1922

2023
export default function SettingsTab({
2124
scrollSyncEnabled,
2225
onScrollSyncChange,
26+
attributionEnabled,
27+
onAttributionChange,
28+
currentFormat,
2329
}: SettingsTabProps) {
2430
const [errorOverlayCollapsed, setErrorOverlayCollapsed] = usePreference('errorOverlayCollapsed');
2531
const [isCapturing, setIsCapturing] = useState(false);
@@ -93,6 +99,19 @@ export default function SettingsTab({
9399
Show errors as a small indicator instead of expanded panel
94100
</span>
95101
</label>
102+
{currentFormat === 'q2-debug' && (
103+
<label className="setting-toggle">
104+
<input
105+
type="checkbox"
106+
checked={attributionEnabled}
107+
onChange={(e) => onAttributionChange(e.target.checked)}
108+
/>
109+
<span className="setting-name">Authorship</span>
110+
<span className="setting-description">
111+
Highlight who wrote each part of the document
112+
</span>
113+
</label>
114+
)}
96115
<div style={{ marginTop: '16px' }}>
97116
<button
98117
className="screenshot-button"

hub-client/src/services/preferences/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const UserPreferencesSchema = z.object({
99
version: z.literal(1),
1010
scrollSyncEnabled: z.boolean(),
1111
errorOverlayCollapsed: z.boolean(),
12+
attributionEnabled: z.boolean(),
1213
colorScheme: ColorSchemeSchema,
1314
});
1415

@@ -23,6 +24,7 @@ export const DEFAULT_PREFERENCES: UserPreferences = {
2324
version: 1,
2425
scrollSyncEnabled: true,
2526
errorOverlayCollapsed: true, // collapsed by default
27+
attributionEnabled: false,
2628
colorScheme: 'auto',
2729
};
2830

0 commit comments

Comments
 (0)