From f99d0a5db3bf4626f5ab3a9316d69cc3798e94f5 Mon Sep 17 00:00:00 2001 From: yousefed Date: Fri, 9 Oct 2026 11:52:11 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20keep=20the=20compared?= =?UTF-8?q?=20versions=20when=20the=20diff=20fixes=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A change of the "Version diff fixes" select created the editor again. The History panel then opened again and selected the latest version, so the selected version and the version it was compared to were lost. BlockNote reads the experimental options each time it shows a version. The editor now keeps one options object, changes it, and shows the selected versions again. The editor is not created again. Signed-off-by: yousefed --- .../doc-editor/components/BlockNoteEditor.tsx | 23 +++++++++++++++---- .../components/VersionHistoryDebug.tsx | 4 +++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx index 86ca3636f9..fa0878a5b0 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx @@ -167,7 +167,9 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => { const historyDebugSettings = useRef( undefined, ); - // The editor reads these once, so changing them recreates it. + // BlockNote reads this object each time it shows a version, so a change + // applies without creating the editor again (which would lose the selection). + const [experimentalOptions] = useState(() => ({})); const [experimentalDiffs, setExperimentalDiffs] = useState({}); const historyDefaults = { @@ -291,7 +293,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => { return cursorElement; }, showCursorLabels: showCursorLabels as 'always' | 'activity', - experimental: experimentalDiffs, + experimental: experimentalOptions, }, dropCursor: { color: 'var(--c--contextuals--background--semantic--brand--tertiary)', @@ -389,7 +391,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => { aiExtension, cursorName, docUserStore, - experimentalDiffs, + experimentalOptions, langLocalesBN, langLocalesBNMultiColumn, langLocalesBNAI, @@ -475,7 +477,20 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => { initialSettings: historyDebugSettings.current ?? historyDefaults, canCreate: !!doc.abilities.partial_update, experimental: experimentalDiffs, - onExperimentalChange: setExperimentalDiffs, + onExperimentalChange: (experimental) => { + experimentalOptions.versionDiffFixes = + experimental.versionDiffFixes; + setExperimentalDiffs(experimental); + // Show the selected versions again with the new setting. + const mode = + editor.getExtension('versioning'); + const state = mode?.store.state; + if (mode && state?.mode === 'versions') { + void mode.select(state.displayed, { + compareTo: state.compareTo, + }); + } + }, onApply: async (settings) => { historyDebugSettings.current = settings; const mode = diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/VersionHistoryDebug.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/VersionHistoryDebug.tsx index e404d46ee7..a2af199c06 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/VersionHistoryDebug.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/VersionHistoryDebug.tsx @@ -384,7 +384,9 @@ export const VersionHistoryDebug = ({ ))} - {t('Experimental. Changing this reloads the editor.')} + {t( + 'Experimental. Changing this shows the selected versions again.', + )}