fix(editor): forget the citing form on Back, refuse sparse paths

This commit is contained in:
bchanot committed 2026-11-15 17:42:26 +01:00
1 parent 7a5684aace
commit 6c0f913104
5 files changed
+30 -3

No files matched your search

+3 -1
View File
@@ -44,7 +44,9 @@ const isId = (value: unknown): value is string =>
/** A finding path no deeper than the tree allows, each id within the cap. */
const isPath = (path: unknown): path is string[] =>
Array.isArray(path) && path.length <= MAX_FINDING_PATH && path.every(isId)
Array.isArray(path) &&
path.length <= MAX_FINDING_PATH &&
Array.from(path).every(isId)
/** A finding or zone key as the tree builds it, or null when `raw` is no such key. */
function sanitizeKey(raw: unknown): ElementKey | null {
+1 -1
View File
@@ -623,7 +623,7 @@ export function useEditorNavigation(
...useFindingLayer(ctx),
...useCitationsLayer(ctx, openers),
...useLeavingMoves(base.go, useAskLeaving(ctx, base.state)),
references: useReferenceMoves(ctx, base.trace),
references: useReferenceMoves(ctx, base.trace, base.state.reference),
citationsTrigger: useCallback(() => triggerOf(openers), [openers]),
guards,
trace: base.trace,
+8 -1
View File
@@ -1,5 +1,6 @@
import { useCallback, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import type { ElementKey } from '@faunosteo/core-wasm/types'
import type { NavigationState } from './navigation'
import type { LayerContext, MoveTrace } from './useEditorNavigation'
/** The reference a creation just made: the library shows a notice for it, once per serial. */
@@ -169,8 +170,14 @@ function useFilter(ctx: LayerContext, trace: MoveTrace) {
export function useReferenceMoves(
ctx: LayerContext,
trace: MoveTrace,
view: NavigationState['reference'],
): ReferenceMoves {
const held = useRef<Held>({ opener: null, cite: null }).current
const creating = view !== null && 'create' in view
// A Back that removes the creation dialog leaves no citing form to answer.
useEffect(() => {
if (!creating) held.cite = null
}, [creating, held])
const opener = useCallback((): HTMLElement | null => {
const element = held.opener
return element?.isConnected && !element.closest('[hidden]') ? element : null