Skip to content

Commit

Permalink
feat(timetable): allow ctrl/cmd + up/down to go to top or bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Oct 6, 2017
1 parent 9074072 commit 20b348e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/editor/components/timetable/TimetableGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ export default class TimetableGrid extends Component {
}
}

/**
* Handles a keypress event when the Timetable Grid is focused.
* This occurs when an EditableCell is not in focus, but the grid is.
* Whenever an EditableCell loses focus by an end in editing, the focus should
* bubble up to this component.
*/
handleKeyPress = (evt) => {
const {
activeCell,
data,
setActiveCell,
scrollToColumn,
scrollToRow,
Expand All @@ -68,29 +75,65 @@ export default class TimetableGrid extends Component {
evt.preventDefault()
// override ArrowKeyStepper
evt.stopPropagation()

// check if done with command key or ctrl
if (evt.metaKey || evt.ctrlKey) {
// move all the way to the first column
updateScroll(scrollToRow, 0)
} else {
this.offsetScrollCol(-1)
}

// retain active focus on the grid
this._focusOnGrid()
break
case 38: // up
// check if done with command key or ctrl
if (evt.metaKey || evt.ctrlKey) {
// prevent default up behavior
evt.preventDefault()
// override ArrowKeyStepper
evt.stopPropagation()

// move all the way to top
updateScroll(0, scrollToColumn)

// retain active focus on the grid
this._focusOnGrid()
}
break
case 39: // right
// prevent browser back
evt.preventDefault()
// override ArrowKeyStepper
evt.stopPropagation()

// check if done with command key or ctrl
if (evt.metaKey || evt.ctrlKey) {
// move all the way to the first column
updateScroll(scrollToRow, this._getColumnCount() - 1)
} else {
this.offsetScrollCol(1)
}

// retain active focus on the grid
this._focusOnGrid()
break
case 40: // down
// check if done with command key or ctrl
if (evt.metaKey || evt.ctrlKey) {
// prevent default up behavior
evt.preventDefault()
// override ArrowKeyStepper
evt.stopPropagation()

// move all the way to the bottom
updateScroll(data.length - 1, scrollToColumn)

// retain active focus on the grid
this._focusOnGrid()
}
break
case 67:
// handle copy
if (evt.ctrlKey) {
Expand Down

0 comments on commit 20b348e

Please sign in to comment.