refactor(editor): Task 2 round 2, locals and line limits

This commit is contained in:
bchanot committed 2026-11-13 19:45:50 +01:00
1 parent b703333b20
commit 20905adf72
10 files changed
+258 -168

No files matched your search

+28 -17
View File
@@ -450,40 +450,51 @@ function useCitedBy(state: NavigationState, openers: Openers) {
}
/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */
export function useEditorNavigation(
initialTab: EditorTabId,
initialView?: EditorView | null,
): EditorNavigation {
/** The reducer and the move machinery every other part of the hook builds on. */
function useNavBase(initialTab: EditorTabId, initialView?: EditorView | null) {
const [state, dispatch] = useReducer(navigationReducer, null, () =>
initialNavigation(initialTab, initialView),
)
const { trace, mark } = useMoveTrace()
const { move, go, live, announce } = useGo(dispatch, trace)
return { state, dispatch, trace, mark, ...useGo(dispatch, trace) }
}
/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */
export function useEditorNavigation(
initialTab: EditorTabId,
initialView?: EditorView | null,
): EditorNavigation {
const base = useNavBase(initialTab, initialView)
const openers = useRef<Openers>({
citations: { current: null },
citedBy: { current: null },
section: { current: null },
}).current
const guards = useGuards()
const receipts = useReceipts(dispatch)
useMoveFocus(move, state, receipts.outcomes, dispatch, openers)
useCitedBy(state, openers)
const ctx = { dispatch, announce, guards, mark }
const receipts = useReceipts(base.dispatch)
useMoveFocus(base.move, base.state, receipts.outcomes, base.dispatch, openers)
useCitedBy(base.state, openers)
const ctx = {
dispatch: base.dispatch,
announce: base.announce,
guards,
mark: base.mark,
}
return {
state,
live,
announce,
state: base.state,
live: base.live,
announce: base.announce,
consumed: receipts.consumed,
selectTab: useTabSelect(dispatch, mark),
...useSectionMoves(go, openers),
selectTab: useTabSelect(base.dispatch, base.mark),
...useSectionMoves(base.go, openers),
...useFindingLayer(ctx),
...useSheetLayer(ctx, openers),
...useLeavingMoves(go, guards),
...useLeavingMoves(base.go, guards),
citationsTrigger: useCallback(() => triggerOf(openers), [openers]),
guards,
trace,
trace: base.trace,
restoreView: useCallback(
(view: EditorView) => dispatch({ type: 'restore_view', view }),
(view: EditorView) => base.dispatch({ type: 'restore_view', view }),
[],
),
}