Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arrow key and tab/enter table editor navigation #1965

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
69d8d23
add all tab/enter/arrow controls
deundrewilliams Jan 26, 2022
d77b3ea
update tests to work with all arrows and tab
deundrewilliams Jan 26, 2022
f0a25e1
Merge branch 'dev/27-pyrite' into issue/726-table-nav
deundrewilliams Jan 26, 2022
09be908
Merge branch 'dev/27-pyrite' into issue/726-table-nav
deundrewilliams Jan 27, 2022
e03153d
add right navigation from rightmost cell
deundrewilliams Jan 31, 2022
74c18ca
add shift+tab left navigation
deundrewilliams Feb 1, 2022
fa4f54c
add left nav when in leftmost column
deundrewilliams Feb 1, 2022
f693f19
update tests to use common editor object
deundrewilliams Feb 3, 2022
ccc8584
update totalCols reference
deundrewilliams Feb 3, 2022
6455b0b
add tabbing to table option buttons
deundrewilliams Feb 8, 2022
e3219a6
change dropdown cell colors on focus
deundrewilliams Feb 9, 2022
c3465d5
highlight dropdown cells when using keyboard, add tests
deundrewilliams Feb 14, 2022
bab7faf
add deselect functionality
deundrewilliams Feb 17, 2022
9b0a5ac
run prettier
deundrewilliams Feb 17, 2022
56a92be
remove commented code
deundrewilliams Feb 17, 2022
e0db51d
add ability to navigate out of table with up/down arrow keys
deundrewilliams Feb 22, 2022
7a5c54a
shorten numCols retrieval
deundrewilliams Feb 28, 2022
7efaec0
fix arrowup from nodes in editor
deundrewilliams Mar 3, 2022
02eb2ad
fix shift+tab bug on bottom cell control option
deundrewilliams Mar 3, 2022
1c3192d
fix selection when exiting table with arrow keys
deundrewilliams Mar 3, 2022
57ebde4
add comments
deundrewilliams Mar 17, 2022
f66df77
clean up code
deundrewilliams Aug 23, 2022
ac9dde4
Merge branch 'dev/30-howlite' into issue/726-table-nav
FrenjaminBanklin Jan 10, 2023
a8b4b7b
726 Merged changes from current dev branch, fixed breaking tests.
FrenjaminBanklin Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 74 additions & 24 deletions packages/obonode/obojobo-chunks-table/editor-registration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Transforms, Node, Range, Path, Editor, Element } from 'slate'
import { Transforms, Node, Range, Editor, Element } from 'slate'

import KeyDownUtil from 'obojobo-document-engine/src/scripts/oboeditor/util/keydown-util'
//import ClipboardUtil from 'obojobo-document-engine/src/scripts/oboeditor/util/keydown-util'
Expand Down Expand Up @@ -41,36 +41,86 @@ const plugins = {
// Editable Plugins - These are used by the PageEditor component to augment React functions
// They affect individual nodes independently of one another
onKeyDown(entry, editor, event) {
function moveCursor(direction) {
// Getting the cell in which we last clicked on.
const [node, row, col] = editor.selection.anchor.path

let nextPath

// Calculate next path based on direction given
switch (direction) {
case 'down':
nextPath = [node, row + 1, col]
break
case 'right':
nextPath = [node, row, col + 1]
break
case 'up':
nextPath = [node, row - 1, col]
break
case 'left':
nextPath = [node, row, col - 1]
break
}

// If next path is valid, jump to it
if (Node.has(editor, nextPath)) {
const focus = Editor.start(editor, nextPath)
const anchor = Editor.end(editor, nextPath)
Transforms.setSelection(editor, {
focus,
anchor
})
} else if (direction === 'right' && Node.has(editor, (nextPath = [node, row + 1, 0]))) {
// If moving right but already at rightmost cell, move to beginning of the row below
const focus = Editor.start(editor, nextPath)
const anchor = Editor.end(editor, nextPath)
Transforms.setSelection(editor, {
focus,
anchor
})
}
}

switch (event.key) {
case 'Backspace':
case 'Delete':
return KeyDownUtil.deleteNodeContents(event, editor, entry, event.key === 'Delete')

case 'Enter':
case 'ArrowDown':
event.preventDefault()
moveCursor('down')
break

case 'Tab':
// If editing text, allow tab navigation to dropdown menu
if (Range.isCollapsed(editor.selection)) break

event.preventDefault()
moveCursor('right')
break

case 'ArrowRight':
// If editing text, don't move to next cell
if (Range.isCollapsed(editor.selection)) break

event.preventDefault()
moveCursor('right')
break

case 'ArrowLeft':
// If editing text, don't move to next cell
if (Range.isCollapsed(editor.selection)) break

event.preventDefault()
moveCursor('left')
break

case 'ArrowUp':
event.preventDefault()
if (Range.isCollapsed(editor.selection)) {
// Getting the table object.
const [tablePath] = Editor.nodes(editor, {
mode: 'lowest',
match: nodeMatch => Element.isElement(nodeMatch)
})

// Getting the cell in which we last clicked on.
const cellPath = tablePath[1]

// Check if there is a row below this one
const siblingPath = Path.next(cellPath.slice(0, -1))
if (Node.has(editor, siblingPath)) {
// If there is, jump down to the cell
// below the current one
const focus = Editor.start(editor, siblingPath.concat(cellPath[cellPath.length - 1]))
const anchor = Editor.end(editor, siblingPath.concat(cellPath[cellPath.length - 1]))
Transforms.setSelection(editor, {
focus,
anchor
})
}
}
moveCursor('up')
break
}
},
renderNode(props) {
Expand Down
Loading