/** * @class Keyboard * @classdesc Сlass to handle the keystrokes * * @module Keyboard * * @author CodeX Team (team@ifmo.su) * @copyright CodeX Team 2017 * @license The MIT License (MIT) * @version 2.0.0 */ /** * @typedef {Keyboard} Keyboard */ export default class Keyboard extends Module { /** * @constructor */ constructor({config}) { super({config}); } /** * Handler on Editor for keyboard keys at keydown event * * @param {KeyboardEvent} event */ keyboardListener(event) { switch(event.keyCode) { case _.keyCodes.BACKSPACE: _.log('Backspace key pressed'); break; case _.keyCodes.ENTER: _.log('Enter key pressed'); this.enterPressed(event); break; case _.keyCodes.DOWN: case _.keyCodes.RIGHT: _.log('Right/Down key pressed'); this.arrowRightAndDownPressed(); break; case _.keyCodes.UP: case _.keyCodes.LEFT: _.log('Left/Up key pressed'); this.arrowLeftAndUpPressed(); break; default: break; } } /** * Handle pressing enter key * * @param {KeyboardEvent} event */ enterPressed(event) { /** * @todo check settings of "allowLinebreaks" plugin */ event.preventDefault(); /** * Insert new block with data below current block */ this.Editor.BlockManager.split(); } /** * Handle right and down keyboard keys */ arrowRightAndDownPressed() { this.Editor.BlockManager.navigateNext(); } /** * Handle left and up keyboard keys */ arrowLeftAndUpPressed() { this.Editor.BlockManager.navigatePrevious(); } }