fix(editor): five locals in stepHistory and MoreTabs, sync tag in tests

This commit is contained in:
bchanot committed 2026-11-14 18:52:41 +01:00
1 parent 08fab77d0e
commit bb35e86dbb
5 files changed
+48 -35

No files matched your search

+13 -9
View File
@@ -148,28 +148,32 @@ function MoreList({ more, active, onPick }: MoreListProps) {
}
/**
* The panel of a tab picked in « Plus » takes the focus once that tab is the shown one: the
* entry that held it is gone with the list, so the focus would fall to the page.
* The choice of a tab in « Plus »: the menu closes, and the panel of the tab picked takes
* the focus once that tab is the shown one (the entry that held it is gone with the list,
* so the focus would fall to the page).
*/
function usePanelFocus(active: EditorTabId) {
function usePanelPick(
active: EditorTabId,
onSelect: MoreTabsProps['onSelect'],
close: () => void,
) {
const [wanted, setWanted] = useState<EditorTabId | null>(null)
useEffect(() => {
if (wanted === null || wanted !== active) return
document.getElementById(panelDomId(active))?.focus()
setWanted(null)
}, [wanted, active])
return setWanted
return (tab: EditorTabId) => {
if (onSelect(tab) !== false) setWanted(tab)
close()
}
}
/** Below 640 px: « Plus » and its dropdown of the tabs that do not fit. */
function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
const t = useT()
const { open, close, toggle } = useMoreMenu(active)
const wantPanel = usePanelFocus(active)
const pick = (tab: EditorTabId) => {
if (onSelect(tab) !== false) wantPanel(tab)
close()
}
const pick = usePanelPick(active, onSelect, close)
useMoreDismiss(open, close)
return (
<>
+11 -2
View File
@@ -69,6 +69,16 @@ export function commit<R>(
return commitBatch(api, [command], accept)
}
/** A step's patch with the finding it brought back, revealed (null when none). */
function withReveal(
patch: Partial<EditorState>,
before: string,
after: string,
): Partial<EditorState> {
const key = appearedFinding(before, after)
return { ...patch, revealed: key ? { key } : null }
}
export function stepHistory(
api: StoreApi,
direction: 'undo' | 'redo',
@@ -82,8 +92,7 @@ export function stepHistory(
const replaced = preview.replaceDocument(step.text)
if (!replaced.ok) return replaced
const patch = replacedPatch(state, step.text, replaced.state, step.history)
const key = appearedFinding(state.documentText, step.text)
api.set({ ...patch, revealed: key ? { key } : null })
api.set(withReveal(patch, state.documentText, step.text))
return { ok: true }
}