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