Improve keyboard navigation in sheets
This commit is contained in:
parent
48309349ae
commit
dfce198fe5
|
@ -1,7 +1,8 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext, onMount } from "svelte"
|
import { getContext, onMount } from "svelte"
|
||||||
|
|
||||||
const { rows, selectedCellId, columns, selectedCellRow } = getContext("sheet")
|
const { rows, selectedCellId, columns, selectedCellRow, stickyColumn } =
|
||||||
|
getContext("sheet")
|
||||||
|
|
||||||
const handleKeyDown = e => {
|
const handleKeyDown = e => {
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
|
@ -24,29 +25,36 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const changeSelectedColumn = delta => {
|
const changeSelectedColumn = delta => {
|
||||||
const cellId = $selectedCellId
|
if (!$selectedCellId) {
|
||||||
if (!cellId) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const cols = $columns
|
const cols = $columns
|
||||||
const split = cellId.split("-")
|
const split = $selectedCellId.split("-")
|
||||||
const columnName = split[1]
|
const columnName = split[1]
|
||||||
const column = cols.findIndex(col => col.name === columnName)
|
let newColumnName
|
||||||
const newColumn = cols[column + delta]
|
if (columnName === $stickyColumn?.name) {
|
||||||
if (newColumn) {
|
const index = delta - 1
|
||||||
$selectedCellId = `${split[0]}-${newColumn.name}`
|
newColumnName = $columns[index]?.name
|
||||||
|
} else {
|
||||||
|
const index = cols.findIndex(col => col.name === columnName) + delta
|
||||||
|
if (index === -1) {
|
||||||
|
newColumnName = $stickyColumn?.name
|
||||||
|
} else {
|
||||||
|
newColumnName = cols[index]?.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newColumnName) {
|
||||||
|
$selectedCellId = `${split[0]}-${newColumnName}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const changeSelectedRow = delta => {
|
const changeSelectedRow = delta => {
|
||||||
const row = $selectedCellRow
|
if (!$selectedCellRow) {
|
||||||
const cellId = $selectedCellId
|
|
||||||
if (!row) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const newRow = $rows[row.__idx + delta]
|
const newRow = $rows[$selectedCellRow.__idx + delta]
|
||||||
if (newRow) {
|
if (newRow) {
|
||||||
const split = cellId.split("-")
|
const split = $selectedCellId.split("-")
|
||||||
$selectedCellId = `${newRow._id}-${split[1]}`
|
$selectedCellId = `${newRow._id}-${split[1]}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue