-
Notifications
You must be signed in to change notification settings - Fork 5
/
prefix-key.js
49 lines (46 loc) · 1.42 KB
/
prefix-key.js
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
"use strict";
/* Support a prefix key with multiple suffix keys */
/* For licensing information, refer to LICENSE.md. */
function PrefixKey(key, modifiers, description) {
this.modal = this.centeredModal(description);
this.suffixes = [];
this.handlers = [];
var that = this;
this.prefix = new Key(key, modifiers, function () {
that.enableSuffixes();
that.modal.show();
});
}
PrefixKey.prototype.enableSuffixes = function () {
var that = this;
this.suffixes.forEach(function (x) {
var h = new Key(x.key, x.modifiers, function () {
that.disableSuffixes();
x.cb();
that.modal.close();
// Phoenix.reload();
});
h.enable();
that.handlers.push(h);
});
};
PrefixKey.prototype.disableSuffixes = function () {
this.handlers.forEach( function (x) {
x.disable();
});
this.handlers = [];
};
PrefixKey.prototype.addSuffix = function (key, modifiers, cb) {
this.suffixes.push({key: key, modifiers: modifiers, cb: cb});
};
PrefixKey.prototype.centeredModal = function (message) {
var result = new Modal();
result.text = message;
var screen_frame = Screen.main().frameInRectangle();
var result_frame = result.frame();
result.origin = {
x: 0.5 * (screen_frame.width - result_frame.width),
y: 0.5 * (screen_frame.height - result_frame.height),
};
return result;
};