Fix issue with pasting from multi to single cell

This commit is contained in:
Andrew Kingston 2024-06-23 15:08:01 +01:00
parent eabb6c94d0
commit 06aa4ba09c
No known key found for this signature in database
2 changed files with 12 additions and 12 deletions

View File

@ -47,9 +47,9 @@
} }
// Sugar for preventing default // Sugar for preventing default
const handle = async fn => { const handle = fn => {
e.preventDefault() e.preventDefault()
await fn() fn()
} }
// Handle certain key presses regardless of selection state // Handle certain key presses regardless of selection state

View File

@ -16,18 +16,19 @@ export const deriveStores = context => {
const { clipboard, focusedCellAPI, selectedCellCount, config } = context const { clipboard, focusedCellAPI, selectedCellCount, config } = context
// Derive whether or not we're able to copy // Derive whether or not we're able to copy
const copyAllowed = derived( const copyAllowed = derived(focusedCellAPI, $focusedCellAPI => {
[focusedCellAPI, selectedCellCount], return $focusedCellAPI != null
([$focusedCellAPI, $selectedCellCount]) => { })
return $focusedCellAPI || $selectedCellCount
}
)
// Derive whether or not we're able to paste // Derive whether or not we're able to paste
const pasteAllowed = derived( const pasteAllowed = derived(
[clipboard, focusedCellAPI, selectedCellCount, config], [clipboard, focusedCellAPI, selectedCellCount, config],
([$clipboard, $focusedCellAPI, $selectedCellCount, $config]) => { ([$clipboard, $focusedCellAPI, $selectedCellCount, $config]) => {
if ($clipboard.value == null || !$config.canEditRows) { if (
$clipboard.value == null ||
!$config.canEditRows ||
!$focusedCellAPI
) {
return false return false
} }
@ -40,8 +41,7 @@ export const deriveStores = context => {
) { ) {
return false return false
} }
return true
return $focusedCellAPI || $selectedCellCount
} }
) )
@ -183,7 +183,7 @@ export const createActions = context => {
get(focusedCellAPI).setValue(value[0][0]) get(focusedCellAPI).setValue(value[0][0])
} else { } else {
// Select the new cells to paste into, then paste // Select the new cells to paste into, then paste
selectedCells.actions.updateTarget(targetCellId) selectedCells.actions.selectRange($focusedCellId, targetCellId)
await pasteIntoSelectedCells(value) await pasteIntoSelectedCells(value)
} }
} }