diff --git a/openspec/changes/sidepanel-ux-improvements/tasks.md b/openspec/changes/sidepanel-ux-improvements/tasks.md index b2e0710..499acb8 100644 --- a/openspec/changes/sidepanel-ux-improvements/tasks.md +++ b/openspec/changes/sidepanel-ux-improvements/tasks.md @@ -14,7 +14,7 @@ ## 3. Focus and caret/scroll restore - [x] 3.1 In `loadNoteForTab`, after setting `editor.value`, restore caret via `setSelectionRange` with offsets clamped to content length (default 0 for legacy records), restore `scrollTop` (in `requestAnimationFrame` if layout timing clamps it), and call `editor.focus()` -- [ ] 3.2 Make `reloadFromDB` skip the `editor.value` assignment when fetched content is identical, so remote saves never move the local caret unnecessarily +- [x] 3.2 Make `reloadFromDB` skip the `editor.value` assignment when fetched content is identical, so remote saves never move the local caret unnecessarily - [ ] 3.3 Manually verify focus lands when the panel opens via toolbar action and via keyboard shortcut; caret restore works on panel open, tab switch, and SPA navigation ## 4. Adjustable font size diff --git a/sidepanel/sidepanel.js b/sidepanel/sidepanel.js index 301643a..a6f58e7 100644 --- a/sidepanel/sidepanel.js +++ b/sidepanel/sidepanel.js @@ -202,9 +202,14 @@ async function reloadFromDB() { if (!currentKey) return; try { const note = await getNoteByKey(currentKey); - isLoadingContent = true; - editor.value = note ? note.content : ''; - isLoadingContent = false; + const content = note ? note.content : ''; + // Skip the assignment when content is unchanged: setting editor.value + // would needlessly reset this panel's caret to the start. + if (content !== editor.value) { + isLoadingContent = true; + editor.value = content; + isLoadingContent = false; + } currentNote = note; updateStatus('Saved'); deferredReload = false;