arrow.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.keydownBehavior = void 0;
  6. var _utils = require("../../utils");
  7. /**
  8. * This file should contain behavior for arrow keys as described here:
  9. * https://w3c.github.io/uievents-code/#key-arrowpad-section
  10. */
  11. const keydownBehavior = [{
  12. // TODO: implement for contentEditable
  13. matches: (keyDef, element) => (keyDef.key === 'ArrowLeft' || keyDef.key === 'ArrowRight') && (0, _utils.isElementType)(element, ['input', 'textarea']),
  14. handle: (keyDef, element) => {
  15. var _ref;
  16. const {
  17. selectionStart,
  18. selectionEnd
  19. } = (0, _utils.getSelectionRange)(element);
  20. const direction = keyDef.key === 'ArrowLeft' ? -1 : 1;
  21. const newPos = (_ref = selectionStart === selectionEnd ? (selectionStart != null ? selectionStart :
  22. /* istanbul ignore next */
  23. 0) + direction : direction < 0 ? selectionStart : selectionEnd) != null ? _ref :
  24. /* istanbul ignore next */
  25. 0;
  26. (0, _utils.setSelectionRange)(element, newPos, newPos);
  27. }
  28. }];
  29. exports.keydownBehavior = keydownBehavior;