feat: capture caret/scroll in editor autosave

This commit is contained in:
Fabio Montefuscolo 2026-08-03 22:11:20 +02:00
parent 6a0532592e
commit 6db41de485
2 changed files with 6 additions and 2 deletions

View file

@ -7,7 +7,7 @@
## 2. Caret persistence in the side panel
- [ ] 2.1 In `sidepanel/sidepanel.js`, pass current caret (`selectionStart`/`selectionEnd`) and `scrollTop` to `saveNote` in the existing autosave (`doSave`)
- [x] 2.1 In `sidepanel/sidepanel.js`, pass current caret (`selectionStart`/`selectionEnd`) and `scrollTop` to `saveNote` in the existing autosave (`doSave`)
- [ ] 2.2 Track caret-only movement via `document` `selectionchange` (filtered to the editor) and editor `scroll`; debounce ~800ms into a caret-only save that calls `saveNote` without broadcasting; skip it while a content autosave is pending
- [ ] 2.3 Flush any pending caret-only save on editor `blur` and on `visibilitychange` → hidden

View file

@ -127,7 +127,11 @@ async function doSave() {
favIconUrl: tab.favIconUrl || '',
};
const saved = await saveNote(currentKey, editor.value, pageMeta);
const saved = await saveNote(currentKey, editor.value, pageMeta, {
caretStart: editor.selectionStart,
caretEnd: editor.selectionEnd,
scrollTop: editor.scrollTop,
});
currentNote = saved;
updateStatus('Saved');