Fix crash when using up and down arrows in new row

This commit is contained in:
Andrew Kingston 2024-06-24 14:48:15 +01:00
parent dedf264185
commit d923f4edb2
No known key found for this signature in database
1 changed files with 7 additions and 8 deletions

View File

@ -2,6 +2,7 @@
import { getContext, onMount } from "svelte"
import { debounce } from "../../../utils/utils"
import { getCellID, parseCellID } from "../lib/utils"
import { NewRowID } from "../lib/constants"
const {
rows,
@ -19,6 +20,7 @@
selectedCells,
cellSelection,
columnLookupMap,
focusedRowId,
} = getContext("grid")
const ignoredOriginSelectors = [
@ -69,14 +71,6 @@
// Handle certain key presses if we have cells selected
if ($selectedCellCount) {
switch (e.key) {
case "ArrowLeft":
return handle(() => changeFocusedColumn(-1, e.shiftKey))
case "ArrowRight":
return handle(() => changeFocusedColumn(1, e.shiftKey))
case "ArrowUp":
return handle(() => changeFocusedRow(-1, e.shiftKey))
case "ArrowDown":
return handle(() => changeFocusedRow(1, e.shiftKey))
case "Escape":
return handle(selectedCells.actions.clear)
case "Delete":
@ -215,6 +209,11 @@
// Changes the focused cell by moving it up or down to a new row
const changeFocusedRow = (delta, shiftKey) => {
// Ignore for new row component
if ($focusedRowId === NewRowID) {
return
}
// Determine which cell we are working with
let sourceCellId = $focusedCellId
if (shiftKey && $selectedCellCount) {