control.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.keydownBehavior = void 0;
var _utils = require("../../utils");
var _shared = require("../shared");
/**
* This file should contain behavior for arrow keys as described here:
* https://w3c.github.io/uievents-code/#key-controlpad-section
*/
const keydownBehavior = [{
matches: (keyDef, element) => (keyDef.key === 'Home' || keyDef.key === 'End') && ((0, _utils.isElementType)(element, ['input', 'textarea']) || (0, _utils.isContentEditable)(element)),
handle: (keyDef, element) => {
// This could probably been improved by collapsing a selection range
if (keyDef.key === 'Home') {
(0, _utils.setSelectionRange)(element, 0, 0);
} else {
var _getValue$length, _getValue;
const newPos = (_getValue$length = (_getValue = (0, _utils.getValue)(element)) == null ? void 0 : _getValue.length) != null ? _getValue$length :
/* istanbul ignore next */
0;
(0, _utils.setSelectionRange)(element, newPos, newPos);
}
}
}, {
matches: (keyDef, element) => (keyDef.key === 'PageUp' || keyDef.key === 'PageDown') && (0, _utils.isElementType)(element, ['input']),
handle: (keyDef, element) => {
// This could probably been improved by collapsing a selection range
if (keyDef.key === 'PageUp') {
(0, _utils.setSelectionRange)(element, 0, 0);
} else {
var _getValue$length2, _getValue2;
const newPos = (_getValue$length2 = (_getValue2 = (0, _utils.getValue)(element)) == null ? void 0 : _getValue2.length) != null ? _getValue$length2 :
/* istanbul ignore next */
0;
(0, _utils.setSelectionRange)(element, newPos, newPos);
}
}
}, {
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element) && !(0, _utils.isCursorAtEnd)(element),
handle: (keDef, element, options, state) => {
const {
newValue,
newSelectionStart
} = (0, _utils.calculateNewValue)('', element, state.carryValue, undefined, 'forward');
(0, _shared.fireInputEvent)(element, {
newValue,
newSelectionStart,
eventOverrides: {
inputType: 'deleteContentForward'
}
});
(0, _shared.carryValue)(element, state, newValue);
}
}];
exports.keydownBehavior = keydownBehavior;