fix: skip editor reload when remote content is identical

This commit is contained in:
Fabio Montefuscolo 2026-08-03 22:13:19 +02:00
parent c58d13eafa
commit 8581117708
2 changed files with 9 additions and 4 deletions

View file

@ -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

View file

@ -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;