From 878aa35335b55ea60daecbd6630153c41552085a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sun, 23 Jun 2024 10:34:23 +0100 Subject: [PATCH] Add support for bulk selecting cells via shift key --- .../src/components/grid/cells/DataCell.svelte | 19 +++++++++++++++++-- .../src/components/grid/stores/ui.js | 9 +++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/cells/DataCell.svelte b/packages/frontend-core/src/components/grid/cells/DataCell.svelte index 845f919e4a..e9293f95b2 100644 --- a/packages/frontend-core/src/components/grid/cells/DataCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/DataCell.svelte @@ -12,6 +12,7 @@ config, validation, selectedCells, + selectedCellCount, } = getContext("grid") export let highlighted @@ -83,7 +84,7 @@ } const startSelection = e => { - if (e.button !== 0) { + if (e.button !== 0 || e.shiftKey) { return } selectedCells.actions.startSelecting(cellId) @@ -99,6 +100,20 @@ const stopSelection = () => { selectedCells.actions.stopSelecting() } + + const handleClick = e => { + if (e.shiftKey && $focusedCellId) { + // If we have a focused cell, select the range from that cell to here + selectedCells.actions.setRange($focusedCellId, cellId) + focusedCellId.set(null) + } else if (e.shiftKey && $selectedCellCount) { + // If we already have a selected range of cell, update it + selectedCells.actions.updateTarget(cellId) + } else { + // Otherwise just select this cell + focusedCellId.set(cellId) + } + } focusedCellId.set(cellId)} + on:click={handleClick} width={column.width} > { })) } + const setCellSelectionRange = (source, target) => { + cellSelection.set({ + active: false, + sourceCellId: source, + targetCellId: target, + }) + } + const clearCellSelection = () => { cellSelection.set({ active: false, @@ -288,6 +296,7 @@ export const createActions = context => { startSelecting: startCellSelection, updateTarget: updateCellSelection, stopSelecting: stopCellSelection, + setRange: setCellSelectionRange, clear: clearCellSelection, }, },