fix(editor): Task 1 review round 1, section back pops, scroll proof

This commit is contained in:
bchanot committed 2026-11-13 18:12:19 +01:00
1 parent 792394d3b2
commit 8e4f02620a
7 files changed
+251 -64

No files matched your search

+19 -4
View File
@@ -68,6 +68,8 @@ export function ownedEntry(
owner: HistoryOwner,
): HistoryEntry | null {
const entry = readEntry(state)
// An empty id is no owner: nobody signed in, no sheet known.
if (!owner.sheetId || !owner.userId) return null
const mine = entry?.sheetId === owner.sheetId && entry.userId === owner.userId
return mine ? entry : null
}
@@ -79,13 +81,26 @@ export function layerCount(view: EditorView): number {
return (view.finding ? 1 : 0) + (view.reference ? 1 : 0)
}
/** An Annotations section other than the drawing is a step over it, like a layer. */
function isStepOver(view: EditorView): boolean {
return view.tab === 'annotations' && view.section !== 'drawing'
}
/** True when the move took a layer away, or left a section for its drawing. */
function isRemoval(top: EditorView, view: EditorView): boolean {
if (layerCount(view) < layerCount(top)) return true
const backToDrawing = view.tab === top.tab && isStepOver(top)
return backToDrawing && !isStepOver(view) && layerCount(view) === 0
}
/** What a changed view asks of the history. */
export type HistoryWrite = 'none' | 'push' | 'replace' | 'back'
/**
* A user move to `view`. A layer taken away goes back when the entry holds the view the
* move lands on (the entry that opened the layer), else it replaces; a layer, tab or
* section added pushes, unless the move asked for a replace.
* A user move to `view`. A layer taken away, or a section left for its drawing ("Retour
* au dessin"), goes back when the entry holds the view the move lands on (the entry that
* opened it), else it replaces; a layer, tab or section added pushes, unless the move
* asked for a replace.
*/
export function planWrite(
top: HistoryEntry,
@@ -93,7 +108,7 @@ export function planWrite(
replace: boolean,
): HistoryWrite {
if (sameView(top.view, view)) return 'none'
if (layerCount(view) < layerCount(top.view)) {
if (isRemoval(top.view, view)) {
return top.below && sameView(top.below, view) ? 'back' : 'replace'
}
return replace ? 'replace' : 'push'