Skip to content

Commit 9074072

Browse files
committed
feat(timetable): allow ctrl or cmd right/left to go to end of sheet
Also fix issue with table not moving after getting to edge
1 parent c138c48 commit 9074072

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

lib/editor/components/timetable/TimetableGrid.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ export default class TimetableGrid extends Component {
4141
}
4242

4343
handleKeyPress = (evt) => {
44-
const {activeCell, setActiveCell, scrollToColumn, scrollToRow} = this.props
44+
const {
45+
activeCell,
46+
setActiveCell,
47+
scrollToColumn,
48+
scrollToRow,
49+
updateScroll
50+
} = this.props
4551
switch (evt.keyCode) {
4652
case 8: // DELETE
4753
// TODO: add delete cell value
@@ -57,6 +63,34 @@ export default class TimetableGrid extends Component {
5763
} else {
5864
return setActiveCell(null)
5965
}
66+
case 37: // left
67+
// prevent browser back
68+
evt.preventDefault()
69+
// override ArrowKeyStepper
70+
evt.stopPropagation()
71+
// check if done with command key or ctrl
72+
if (evt.metaKey || evt.ctrlKey) {
73+
// move all the way to the first column
74+
updateScroll(scrollToRow, 0)
75+
} else {
76+
this.offsetScrollCol(-1)
77+
}
78+
this._focusOnGrid()
79+
break
80+
case 39: // right
81+
// prevent browser back
82+
evt.preventDefault()
83+
// override ArrowKeyStepper
84+
evt.stopPropagation()
85+
// check if done with command key or ctrl
86+
if (evt.metaKey || evt.ctrlKey) {
87+
// move all the way to the first column
88+
updateScroll(scrollToRow, this._getColumnCount() - 1)
89+
} else {
90+
this.offsetScrollCol(1)
91+
}
92+
this._focusOnGrid()
93+
break
6094
case 67:
6195
// handle copy
6296
if (evt.ctrlKey) {
@@ -207,6 +241,10 @@ export default class TimetableGrid extends Component {
207241
handleEndEditing = () => {
208242
this.props.setActiveCell(null)
209243
// refocus on grid after editing is done
244+
this._focusOnGrid()
245+
}
246+
247+
_focusOnGrid () {
210248
ReactDOM.findDOMNode(this.grid) && ReactDOM.findDOMNode(this.grid).focus()
211249
}
212250

0 commit comments

Comments
 (0)