From 262ecc81d43f441278b192b824a678233e07b47f Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Mon, 13 Mar 2023 21:31:16 +0100 Subject: [PATCH] fix shift selection bugs --- client/src/components/NiceTable.vue | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/client/src/components/NiceTable.vue b/client/src/components/NiceTable.vue index f936233..ade930a 100644 --- a/client/src/components/NiceTable.vue +++ b/client/src/components/NiceTable.vue @@ -49,16 +49,20 @@ function toggleSorting(columnName: string) { function rowSelection(index: number) { if (shiftState) { - let last = selection[selection.length-1]; - let start = index; - let end = last; - if (last < start) { - start = last; - end = index; - } - for (let i = start; i < end; i++ ) { - if (!selection.includes(i)) { - selection = [...selection, i]; + if (selection.length === 0) { + selection = [index]; + } else { + let last = selection[selection.length-1]; + let start = index; + let end = last; + if (last < start) { + start = last; + end = index; + } + for (let i = start; i <= end; i++ ) { + if (!selection.includes(i)) { + selection = [...selection, i]; + } } } } else if (ctrlState) {