Frontend created and rewritten a few times, with some backend fixes #1
|
@ -205,23 +205,21 @@ defineExpose({
|
||||||
cursor.value = null
|
cursor.value = null
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const N = documents.length
|
||||||
const mod = (a: number, b: number) => ((a % b) + b) % b
|
const mod = (a: number, b: number) => ((a % b) + b) % b
|
||||||
const index = cursor.value !== null ? documents.indexOf(cursor.value) : -1
|
const increment = (i: number, d: number) => mod(i + d, N + 1)
|
||||||
const moveto = mod(index + d, documents.length + 1)
|
const index = cursor.value !== null ? documents.indexOf(cursor.value) : documents.length
|
||||||
|
const moveto = increment(index, d)
|
||||||
cursor.value = documents[moveto] ?? null
|
cursor.value = documents[moveto] ?? null
|
||||||
const tr = document.getElementById(
|
const tr = cursor.value ? document.getElementById(`file-${cursor.value.key}`) : null
|
||||||
`file-${cursor.value.key}`
|
|
||||||
) as HTMLTableRowElement | null
|
|
||||||
if (select) {
|
if (select) {
|
||||||
// Go forwards, possibly wrapping over the end; the last entry is not toggled
|
// Go forwards, possibly wrapping over the end; the last entry is not toggled
|
||||||
let [begin, end] = d > 0 ? [index, moveto] : [moveto, index]
|
let [begin, end] = d > 0 ? [index, moveto] : [moveto, index]
|
||||||
for (let p = begin; p !== end; p = mod(p + 1, documents.length)) {
|
for (let p = begin; p !== end; p = increment(p, 1)) {
|
||||||
const doc = documents[p]
|
if (p === N) continue
|
||||||
if (documentStore.selected.has(doc.key)) {
|
const key = documents[p].key
|
||||||
documentStore.selected.delete(doc.key)
|
if (documentStore.selected.has(key)) documentStore.selected.delete(key)
|
||||||
} else {
|
else documentStore.selected.add(key)
|
||||||
documentStore.selected.add(doc.key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
Loading…
Reference in New Issue
Block a user