fix(diffs): let the native layer own selection restore whenever it saved one

The ownership rule keyed on a deletions-side selection specifically, but the
native layer skips only the EDITABLE additions side. On a read-only diff with
Cmd+F find open, isEditable is false, so the native layer saved an
additions-side selection while the find-mode editor also restored its own --
both drove selection.

Key on whether a native selection exists at all, which is the actual invariant:
the native layer saves exactly what it intends to restore.
This commit is contained in:
Neil
2026-09-10 17:55:33 -07:00
parent 7ec791ed34
commit e4ca24afbb
2 changed files with 5 additions and 4 deletions
@@ -74,7 +74,7 @@ it('reuses matching dormant document history and view state', () => {
editor.finish()
})
it('yields selection restore to the native layer for a deletions-side selection', () => {
it('yields selection restore to the native layer whenever it saved one', () => {
const state = stored()
states.set('native-owned', state)
nativeViews.set('native-owned', { selection: { side: 'deletions' } })
@@ -71,9 +71,10 @@ export const createPierreEditor: EditorFactory<PierreDiffAnnotationData, undefin
// Pierre resumes an edited document only from a complete EditState; dropping diffSession
// makes it rebuild and drop the restored selection. Keep it when the old side is unchanged,
// otherwise fall back to fresh worker-computed hunks.
// Only one layer may drive selection. A saved deletions-side selection is restored natively,
// so hand the editor a rebuilt session there instead of letting it reassert its own.
const nativeOwnsSelection = getPierreNativeView(key)?.selection?.side === 'deletions'
// Only one layer may drive selection. The native layer saves exactly the selections it intends
// to restore (it skips the editable additions side), so any saved selection means it owns the
// restore and the editor must get a rebuilt session rather than reassert its own.
const nativeOwnsSelection = getPierreNativeView(key)?.selection != null
const matchesOldSide =
matchesContent &&
!nativeOwnsSelection &&