MCPcopy
hub / github.com/nadbm/react-datasheet / handleKey

Function handleKey

src/DataSheet.js:249–297  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

247 }
248
249 handleKey (e) {
250 if (e.isPropagationStopped && e.isPropagationStopped()) {
251 return
252 }
253 const keyCode = e.which || e.keyCode
254 const {start, end, editing} = this.getState()
255 const isEditing = editing && !isEmpty(editing)
256 const noCellsSelected = !start || isEmpty(start)
257 const ctrlKeyPressed = e.ctrlKey || e.metaKey
258 const deleteKeysPressed = (keyCode === DELETE_KEY || keyCode === BACKSPACE_KEY)
259 const enterKeyPressed = keyCode === ENTER_KEY
260 const numbersPressed = (keyCode >= 48 && keyCode <= 57)
261 const lettersPressed = (keyCode >= 65 && keyCode <= 90)
262 const latin1Supplement = (keyCode >= 160 && keyCode <= 255)
263 const numPadKeysPressed = (keyCode >= 96 && keyCode <= 105)
264 const currentCell = !noCellsSelected && this.props.data[start.i][start.j]
265 const equationKeysPressed = [
266 187, /* equal */
267 189, /* substract */
268 190, /* period */
269 107, /* add */
270 109, /* decimal point */
271 110
272 ].indexOf(keyCode) > -1
273
274 if (noCellsSelected || ctrlKeyPressed) {
275 return true
276 }
277
278 if (!isEditing) {
279 this.handleKeyboardCellMovement(e)
280 if (deleteKeysPressed) {
281 e.preventDefault()
282 this.clearSelectedCells(start, end)
283 } else if (currentCell && !currentCell.readOnly) {
284 if (enterKeyPressed) {
285 this._setState({editing: start, clear: {}, forceEdit: true})
286 e.preventDefault()
287 } else if (numbersPressed ||
288 numPadKeysPressed ||
289 lettersPressed ||
290 latin1Supplement ||
291 equationKeysPressed) {
292 // empty out cell if user starts typing without pressing enter
293 this._setState({editing: start, clear: start, forceEdit: false})
294 }
295 }
296 }
297 }
298
299 getSelectedCells (data, start, end) {
300 let selected = []

Callers

nothing calls this directly

Calls 1

isEmptyFunction · 0.70

Tested by

no test coverage detected