feat: flush pending caret save on blur and panel hide
This commit is contained in:
parent
79a552f620
commit
fbabcdf750
2 changed files with 16 additions and 1 deletions
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
- [x] 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`)
|
||||||
- [x] 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
|
- [x] 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
|
- [x] 2.3 Flush any pending caret-only save on editor `blur` and on `visibilitychange` → hidden
|
||||||
|
|
||||||
## 3. Focus and caret/scroll restore
|
## 3. Focus and caret/scroll restore
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ function scheduleSave() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doSave() {
|
async function doSave() {
|
||||||
|
saveTimer = null;
|
||||||
if (!currentKey || currentTabId == null) return;
|
if (!currentKey || currentTabId == null) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -219,8 +220,22 @@ editor.addEventListener('blur', () => {
|
||||||
if (deferredReload) {
|
if (deferredReload) {
|
||||||
reloadFromDB();
|
reloadFromDB();
|
||||||
}
|
}
|
||||||
|
flushCaretSave();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (document.visibilityState === 'hidden') {
|
||||||
|
flushCaretSave();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function flushCaretSave() {
|
||||||
|
if (caretTimer) {
|
||||||
|
clearTimeout(caretTimer);
|
||||||
|
doCaretSave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Caret-only persistence
|
// Caret-only persistence
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue