feat: persist caret/scroll fields on note records
This commit is contained in:
parent
abe336c3ef
commit
6a0532592e
2 changed files with 16 additions and 3 deletions
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
## 1. Storage: caret/scroll fields on the note record
|
## 1. Storage: caret/scroll fields on the note record
|
||||||
|
|
||||||
- [ ] 1.1 Extend `saveNote` in `shared/storage.js` with an optional caret parameter (`{ caretStart, caretEnd, scrollTop }`); when provided, write those fields onto the record (both insert and update-in-place paths); when absent, preserve existing fields
|
- [x] 1.1 Extend `saveNote` in `shared/storage.js` with an optional caret parameter (`{ caretStart, caretEnd, scrollTop }`); when provided, write those fields onto the record (both insert and update-in-place paths); when absent, preserve existing fields
|
||||||
- [ ] 1.2 Verify old records without caret fields still load and save unchanged (no IndexedDB version bump)
|
- [x] 1.2 Verify old records without caret fields still load and save unchanged (no IndexedDB version bump)
|
||||||
|
|
||||||
## 2. Caret persistence in the side panel
|
## 2. Caret persistence in the side panel
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,12 @@ export async function getNoteByKey(key) {
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
* @param {string} content — markdown body
|
* @param {string} content — markdown body
|
||||||
* @param {{ pageTitle?: string, favIconUrl?: string }} pageMeta
|
* @param {{ pageTitle?: string, favIconUrl?: string }} pageMeta
|
||||||
|
* @param {{ caretStart?: number, caretEnd?: number, scrollTop?: number }} [caret]
|
||||||
|
* Optional editor caret/scroll state captured at save time. When
|
||||||
|
* omitted, any previously stored caret fields are preserved.
|
||||||
* @returns {Promise<object>} the saved record
|
* @returns {Promise<object>} the saved record
|
||||||
*/
|
*/
|
||||||
export async function saveNote(key, content, pageMeta = {}) {
|
export async function saveNote(key, content, pageMeta = {}, caret) {
|
||||||
const db = await openDB();
|
const db = await openDB();
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
|
||||||
|
|
@ -100,6 +103,11 @@ export async function saveNote(key, content, pageMeta = {}) {
|
||||||
favIconUrl: pageMeta.favIconUrl ?? existing.favIconUrl ?? '',
|
favIconUrl: pageMeta.favIconUrl ?? existing.favIconUrl ?? '',
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
};
|
};
|
||||||
|
if (caret) {
|
||||||
|
updated.caretStart = caret.caretStart ?? 0;
|
||||||
|
updated.caretEnd = caret.caretEnd ?? 0;
|
||||||
|
updated.scrollTop = caret.scrollTop ?? 0;
|
||||||
|
}
|
||||||
req = store.put(updated);
|
req = store.put(updated);
|
||||||
} else {
|
} else {
|
||||||
// Insert new.
|
// Insert new.
|
||||||
|
|
@ -113,6 +121,11 @@ export async function saveNote(key, content, pageMeta = {}) {
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
};
|
};
|
||||||
|
if (caret) {
|
||||||
|
record.caretStart = caret.caretStart ?? 0;
|
||||||
|
record.caretEnd = caret.caretEnd ?? 0;
|
||||||
|
record.scrollTop = caret.scrollTop ?? 0;
|
||||||
|
}
|
||||||
req = store.add(record);
|
req = store.add(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue