Preserve cursor and selection across reloads.

This commit is contained in:
Leo Vasanko 2023-11-20 14:49:15 -08:00
parent 8592d462f2
commit 52beedcef0
3 changed files with 16 additions and 10 deletions

View File

@ -221,7 +221,7 @@ onMounted(() => {
updateModified(); modifiedTimer = setInterval(updateModified, 1000) updateModified(); modifiedTimer = setInterval(updateModified, 1000)
const active = document.querySelector('.cursor') as HTMLElement | null const active = document.querySelector('.cursor') as HTMLElement | null
if (active) { if (active) {
active.scrollIntoView({ block: 'center', behavior: 'smooth' }) active.scrollIntoView({ block: 'center', behavior: 'instant' })
active.focus() active.focus()
} }
}) })

View File

@ -164,15 +164,10 @@ watchEffect(() => {
focusBreadcrumb() focusBreadcrumb()
} }
}) })
let nowkey = ref(0)
let modifiedTimer: any = null
const updateModified = () => {
nowkey.value = Math.floor(Date.now() / 1000)
}
onMounted(() => { onMounted(() => {
const active = document.querySelector('.cursor') as HTMLElement | null const active = document.querySelector('.cursor') as HTMLElement | null
if (active) { if (active) {
active.scrollIntoView({ block: 'center', behavior: 'smooth' }) active.scrollIntoView({ block: 'center', behavior: 'instant' })
active.focus() active.focus()
} }
}) })

View File

@ -1,6 +1,6 @@
import type { FileEntry, FUID, SelectedItems } from '@/repositories/Document' import type { FileEntry, FUID, SelectedItems } from '@/repositories/Document'
import { Doc } from '@/repositories/Document' import { Doc } from '@/repositories/Document'
import { defineStore } from 'pinia' import { defineStore, type StateTree } from 'pinia'
import { collator } from '@/utils' import { collator } from '@/utils'
import { logoutUser } from '@/repositories/User' import { logoutUser } from '@/repositories/User'
import { watchConnect } from '@/repositories/WS' import { watchConnect } from '@/repositories/WS'
@ -11,7 +11,7 @@ export const useMainStore = defineStore({
id: 'main', id: 'main',
state: () => ({ state: () => ({
document: shallowRef<Doc[]>([]), document: shallowRef<Doc[]>([]),
selected: new Set<FUID>(), selected: new Set<FUID>([]),
query: '' as string, query: '' as string,
fileExplorer: null as any, fileExplorer: null as any,
error: '' as string, error: '' as string,
@ -31,7 +31,18 @@ export const useMainStore = defineStore({
} }
}), }),
persist: { persist: {
paths: ['prefs'], paths: ['prefs', 'cursor', 'selected'],
serializer: {
deserialize: (data: string): StateTree => {
const ret = JSON.parse(data)
ret.selected = new Set(ret.selected)
return ret
},
serialize: (tree: StateTree): string => {
tree.selected = Array.from(tree.selected)
return JSON.stringify(tree)
}
},
}, },
actions: { actions: {
updateRoot(root: FileEntry[]) { updateRoot(root: FileEntry[]) {