Skip to content

Commit

Permalink
feat(timetable): allow ctrl or cmd right/left to go to end of sheet
Browse files Browse the repository at this point in the history
Also fix issue with table not moving after getting to edge
  • Loading branch information
evansiroky committed Oct 6, 2017
1 parent c138c48 commit 9074072
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion lib/editor/components/timetable/TimetableGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export default class TimetableGrid extends Component {
}

handleKeyPress = (evt) => {
const {activeCell, setActiveCell, scrollToColumn, scrollToRow} = this.props
const {
activeCell,
setActiveCell,
scrollToColumn,
scrollToRow,
updateScroll
} = this.props
switch (evt.keyCode) {
case 8: // DELETE
// TODO: add delete cell value
Expand All @@ -57,6 +63,34 @@ export default class TimetableGrid extends Component {
} else {
return setActiveCell(null)
}
case 37: // left
// 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, 0)
} else {
this.offsetScrollCol(-1)
}
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)
}
this._focusOnGrid()
break
case 67:
// handle copy
if (evt.ctrlKey) {
Expand Down Expand Up @@ -207,6 +241,10 @@ export default class TimetableGrid extends Component {
handleEndEditing = () => {
this.props.setActiveCell(null)
// refocus on grid after editing is done
this._focusOnGrid()
}

_focusOnGrid () {
ReactDOM.findDOMNode(this.grid) && ReactDOM.findDOMNode(this.grid).focus()
}

Expand Down

0 comments on commit 9074072

Please sign in to comment.