Fix bug when browsing around the end
This commit is contained in:
parent
4f370440d9
commit
cdc936d2d5
|
@ -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