From 4f370440d94f5fd0d75518e2e5079d84029c9d8e Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sun, 5 Nov 2023 16:07:28 +0000 Subject: [PATCH] Shift-Up/Down selection --- .gitignore | 1 - cista-front/.gitignore | 1 + cista-front/src/App.vue | 7 +++++-- cista-front/src/components/FileExplorer.vue | 18 +++++++++++++++--- cista-front/src/components/FileRenameInput.vue | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b73145d..02868b0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ __pycache__/ *.egg-info/ /cista/_version.py /cista/wwwroot/* -/cista-front/components.d.ts # Generated /dist diff --git a/cista-front/.gitignore b/cista-front/.gitignore index 356712c..36cf632 100644 --- a/cista-front/.gitignore +++ b/cista-front/.gitignore @@ -16,6 +16,7 @@ dist dist-ssr coverage *.local +components.d.ts /cypress/videos/ /cypress/screenshots/ diff --git a/cista-front/src/App.vue b/cista-front/src/App.vue index 6c52bbb..79250be 100644 --- a/cista-front/src/App.vue +++ b/cista-front/src/App.vue @@ -92,10 +92,13 @@ const globalShortcutHandler = (event: KeyboardEvent) => { } if (!timer) { // Initial move, then t0 delay until repeats at tr intervals - documentStore.fileExplorer.cursorMove(vert) + const select = event.shiftKey + documentStore.fileExplorer.cursorMove(vert, select) const t0 = 200, tr = 30 timer = setTimeout( - () => timer = setInterval(() => { documentStore.fileExplorer.cursorMove(vert) }, tr), + () => timer = setInterval(() => { + documentStore.fileExplorer.cursorMove(vert, select) + }, tr), t0 - tr ) } diff --git a/cista-front/src/components/FileExplorer.vue b/cista-front/src/components/FileExplorer.vue index ae07793..45ea629 100644 --- a/cista-front/src/components/FileExplorer.vue +++ b/cista-front/src/components/FileExplorer.vue @@ -189,7 +189,6 @@ defineExpose({ editing.value = cursor.value }, cursorSelect() { - console.log('select', documentStore.selected) const doc = cursor.value if (!doc) return if (documentStore.selected.has(doc.key)) { @@ -199,7 +198,7 @@ defineExpose({ } this.cursorMove(1) }, - cursorMove(d: number) { + cursorMove(d: number, select = false) { // Move cursor up or down (keyboard navigation) const documents = sorted(props.documents as FolderDocument[]) if (documents.length === 0) { @@ -208,10 +207,23 @@ defineExpose({ } const mod = (a: number, b: number) => ((a % b) + b) % b const index = cursor.value !== null ? documents.indexOf(cursor.value) : -1 - cursor.value = documents[mod(index + d, documents.length + 1)] ?? null + const moveto = mod(index + d, documents.length + 1) + cursor.value = documents[moveto] ?? null const tr = document.getElementById( `file-${cursor.value.key}` ) as HTMLTableRowElement | null + if (select) { + // Go forwards, possibly wrapping over the end; the last entry is not toggled + let [begin, end] = d > 0 ? [index, moveto] : [moveto, index] + for (let p = begin; p !== end; p = mod(p + 1, documents.length)) { + const doc = documents[p] + if (documentStore.selected.has(doc.key)) { + documentStore.selected.delete(doc.key) + } else { + documentStore.selected.add(doc.key) + } + } + } // @ts-ignore scrolltr = tr if (!scrolltimer) { diff --git a/cista-front/src/components/FileRenameInput.vue b/cista-front/src/components/FileRenameInput.vue index 7368778..82a74ca 100644 --- a/cista-front/src/components/FileRenameInput.vue +++ b/cista-front/src/components/FileRenameInput.vue @@ -3,6 +3,7 @@ ref="input" id="FileRenameInput" type="text" + autocorrect="off" v-model="name" @blur="exit" @keyup.esc="exit"