2019-07-18 00:02:07 +08:00
|
|
|
class Keybind {
|
2019-12-16 03:04:31 +08:00
|
|
|
constructor(keys) {
|
2019-07-18 00:02:07 +08:00
|
|
|
this.key = -1;
|
|
|
|
this.ctrl = false;
|
|
|
|
this.shift = false;
|
|
|
|
this.alt = false;
|
|
|
|
this.meta = false;
|
|
|
|
this.label = '';
|
2019-12-16 03:04:31 +08:00
|
|
|
this.conflict = false;
|
2019-07-18 00:02:07 +08:00
|
|
|
if (keys) {
|
2019-12-16 03:04:31 +08:00
|
|
|
if (isApp && Blockbench.platform == 'darwin' && keys.ctrl && !keys.meta) {
|
2019-07-18 00:02:07 +08:00
|
|
|
keys.meta = true;
|
|
|
|
keys.ctrl = undefined;
|
|
|
|
}
|
2020-10-18 03:54:08 +08:00
|
|
|
if (typeof keys.key == 'string') {
|
|
|
|
keys.key = keys.key.toUpperCase().charCodeAt(0)
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
this.set(keys)
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
set(keys, dflt) {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (!keys || typeof keys !== 'object') return this;
|
2023-02-17 07:18:22 +08:00
|
|
|
this.key = typeof keys.key == 'number' ? keys.key : -1;
|
2019-12-16 03:04:31 +08:00
|
|
|
if (this.ctrl !== null) this.ctrl = (keys.ctrl === null) ? null : (keys.ctrl == true);
|
|
|
|
if (this.shift !== null) this.shift= (keys.shift=== null) ? null : (keys.shift == true);
|
|
|
|
if (this.alt !== null) this.alt = (keys.alt === null) ? null : (keys.alt == true);
|
|
|
|
if (this.meta !== null) this.meta = (keys.meta === null) ? null : (keys.meta == true);
|
|
|
|
if (dflt) {
|
|
|
|
if (dflt.ctrl == null) this.ctrl = null;
|
|
|
|
if (dflt.shift == null) this.shift = null;
|
|
|
|
if (dflt.alt == null) this.alt = null;
|
|
|
|
if (dflt.meta == null) this.meta = null;
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
this.label = this.getText()
|
2019-12-16 03:04:31 +08:00
|
|
|
TickUpdates.keybind_conflicts = true;
|
2019-07-18 00:02:07 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.set({
|
|
|
|
key: -1,
|
|
|
|
ctrl: false,
|
|
|
|
shift: false,
|
|
|
|
alt: false,
|
|
|
|
meta: false
|
2020-10-15 04:50:10 +08:00
|
|
|
}).save();
|
2019-07-18 00:02:07 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
save(save) {
|
|
|
|
if (this.action) {
|
|
|
|
var obj = {
|
|
|
|
key: this.key
|
|
|
|
}
|
|
|
|
if (this.ctrl) obj.ctrl = true
|
|
|
|
if (this.shift) obj.shift = true
|
|
|
|
if (this.alt) obj.alt = true
|
|
|
|
if (this.meta) obj.meta = true
|
|
|
|
|
2023-02-01 06:48:29 +08:00
|
|
|
let key = this.sub_id ? (this.action + '.' + this.sub_id) : this.action;
|
|
|
|
Keybinds.stored[key] = obj
|
2019-07-18 00:02:07 +08:00
|
|
|
if (save !== false) {
|
2019-12-16 03:04:31 +08:00
|
|
|
Keybinds.save();
|
|
|
|
TickUpdates.keybind_conflicts = true;
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2020-03-05 03:56:17 +08:00
|
|
|
|
|
|
|
if (BarItems[this.action] instanceof Action) {
|
2020-10-15 04:50:10 +08:00
|
|
|
BarItems[this.action].updateKeybindingLabel()
|
2020-03-05 03:56:17 +08:00
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2023-02-01 06:48:29 +08:00
|
|
|
setAction(id, sub_id) {
|
2019-07-18 00:02:07 +08:00
|
|
|
var action = BarItems[id]
|
|
|
|
if (!action) {
|
|
|
|
action = Keybinds.extra[id]
|
|
|
|
}
|
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-01 06:48:29 +08:00
|
|
|
this.action = id;
|
|
|
|
this.sub_id = sub_id;
|
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
if (!Keybinds.structure[action.category]) {
|
|
|
|
Keybinds.structure[action.category] = {
|
|
|
|
actions: [],
|
|
|
|
id: action.category,
|
|
|
|
name: tl('category.'+action.category),
|
2019-12-16 03:04:31 +08:00
|
|
|
open: false,
|
|
|
|
conflict: false,
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-01 06:48:29 +08:00
|
|
|
Keybinds.structure[action.category].actions.safePush(action)
|
2019-07-18 00:02:07 +08:00
|
|
|
return this;
|
|
|
|
}
|
2021-07-31 05:12:51 +08:00
|
|
|
getText(colorized = false) {
|
2020-09-15 20:14:14 +08:00
|
|
|
if (this.key < 0) return '';
|
2019-07-18 00:02:07 +08:00
|
|
|
var modifiers = []
|
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
if (this.ctrl) modifiers.push(tl('keys.ctrl'))
|
2021-03-04 22:02:04 +08:00
|
|
|
if (this.ctrl === null) modifiers.push(`[${tl('keys.ctrl')}]`)
|
2019-12-16 03:04:31 +08:00
|
|
|
if (this.shift) modifiers.push(tl('keys.shift'))
|
2021-03-04 22:02:04 +08:00
|
|
|
if (this.shift === null) modifiers.push(`[${tl('keys.shift')}]`)
|
2019-12-16 03:04:31 +08:00
|
|
|
if (this.alt) modifiers.push(tl('keys.alt'))
|
2021-03-04 22:02:04 +08:00
|
|
|
if (this.alt === null) modifiers.push(`[${tl('keys.alt')}]`)
|
2019-12-16 03:04:31 +08:00
|
|
|
if (this.meta) modifiers.push(tl('keys.meta'))
|
2021-03-04 22:02:04 +08:00
|
|
|
if (this.meta === null) modifiers.push(`[${tl('keys.meta')}]`)
|
2019-07-18 00:02:07 +08:00
|
|
|
|
|
|
|
var char = this.getCode()
|
|
|
|
var char_tl = tl('keys.'+char)
|
|
|
|
if (char_tl === ('keys.'+char)) {
|
|
|
|
modifiers.push(capitalizeFirstLetter(char))
|
|
|
|
} else {
|
|
|
|
modifiers.push(char_tl)
|
|
|
|
}
|
2021-07-31 05:12:51 +08:00
|
|
|
if (colorized) {
|
|
|
|
modifiers.forEach((text, i) => {
|
2021-08-03 16:17:42 +08:00
|
|
|
let type = i !== modifiers.length-1
|
|
|
|
? text.match(/\[\w+\]/) ? 'optional' : 'modifier'
|
|
|
|
: 'key'
|
|
|
|
modifiers[i] = `<span class="${type}">${text}</span>`;
|
2021-07-31 05:12:51 +08:00
|
|
|
})
|
|
|
|
return modifiers.join(`<span class="punctuation"> + </span>`);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return modifiers.join(' + ');
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
getCode(key) {
|
|
|
|
if (!key) key = this.key;
|
|
|
|
if (key < 0) {
|
|
|
|
return ''
|
|
|
|
} else if (key >= 112 && key <= 123) {
|
|
|
|
return tl('keys.function', [key-111])
|
|
|
|
} else if (key >= 96 && key <= 105) {
|
|
|
|
return tl('keys.numpad', [key-96])
|
|
|
|
} else if (key >= 4 && key <= 7) {
|
|
|
|
return tl('keys.mouse', [key])
|
|
|
|
}
|
|
|
|
switch (key) {
|
2021-02-20 18:58:53 +08:00
|
|
|
case 1: return 'leftclick';
|
|
|
|
case 2: return 'middleclick';
|
|
|
|
case 3: return 'rightclick';
|
|
|
|
case 9: return 'tab';
|
|
|
|
case 8: return 'backspace';
|
|
|
|
case 13: return 'enter';
|
|
|
|
case 27: return 'escape';
|
|
|
|
case 46: return 'delete';
|
|
|
|
case 46: return 'caps';
|
|
|
|
case 16: return 'shift';
|
|
|
|
case 17: return 'control';
|
|
|
|
case 18: return 'alt';
|
|
|
|
case 32: return 'space';
|
|
|
|
case 93: return 'menu';
|
|
|
|
case 37: return 'left';
|
|
|
|
case 38: return 'up';
|
|
|
|
case 39: return 'right';
|
|
|
|
case 40: return 'down';
|
|
|
|
case 33: return 'pageup';
|
|
|
|
case 34: return 'pagedown';
|
|
|
|
case 35: return 'end';
|
|
|
|
case 36: return 'pos1';
|
|
|
|
case 44: return 'printscreen';
|
|
|
|
case 19: return 'pause';
|
|
|
|
case 1001: return 'mousewheel';
|
|
|
|
|
|
|
|
case 188: return ',';
|
|
|
|
case 190: return '.';
|
|
|
|
case 189: return '-';
|
2023-02-27 03:53:25 +08:00
|
|
|
case 191: return '/';
|
|
|
|
case 219: return '[';
|
|
|
|
case 221: return ']';
|
|
|
|
case 186: return ';';
|
|
|
|
case 222: return "'";
|
|
|
|
case 220: return '\\';
|
|
|
|
case 187: return '=';
|
|
|
|
case 226: return '\\';
|
|
|
|
case 192: return '`';
|
|
|
|
//case 187: return '+';
|
2021-02-20 18:58:53 +08:00
|
|
|
default : return String.fromCharCode(key).toLowerCase();
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
hasKey() {
|
|
|
|
return this.key >= 0;
|
|
|
|
}
|
|
|
|
setConflict() {
|
|
|
|
if (!this.conflict) {
|
|
|
|
this.conflict = true;
|
|
|
|
var action = BarItems[this.action];
|
|
|
|
if (!action) {
|
|
|
|
action = Keybinds.extra[this.action];
|
|
|
|
}
|
|
|
|
if (action && Keybinds.structure[action.category]) {
|
|
|
|
Keybinds.structure[action.category].conflict = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
isTriggered(event) {
|
|
|
|
return (
|
2021-08-03 17:04:40 +08:00
|
|
|
(this.key === event.which || (this.key == 1001 && event instanceof MouseEvent)) &&
|
2021-09-02 04:13:04 +08:00
|
|
|
(this.ctrl === (event.ctrlKey || Pressing.overrides.ctrl) || this.ctrl === null ) &&
|
|
|
|
(this.shift === (event.shiftKey || Pressing.overrides.shift)|| this.shift === null ) &&
|
|
|
|
(this.alt === (event.altKey || Pressing.overrides.alt) || this.alt === null ) &&
|
|
|
|
(this.meta === event.metaKey || this.meta === null )
|
2019-07-18 00:02:07 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
record() {
|
|
|
|
var scope = this;
|
|
|
|
Keybinds.recording = this;
|
|
|
|
var overlay = $('#overlay_message_box').show()
|
2021-01-31 07:12:53 +08:00
|
|
|
var top = limitNumber(window.innerHeight/2 - 200, 30, 800)
|
2019-07-18 00:02:07 +08:00
|
|
|
overlay.find('> div').css('margin-top', top+'px')
|
|
|
|
|
|
|
|
function onActivate(event) {
|
2021-01-17 04:43:36 +08:00
|
|
|
if (event.originalEvent) event = event.originalEvent;
|
|
|
|
|
|
|
|
document.removeEventListener('keyup', onActivate)
|
|
|
|
document.removeEventListener('keydown', onActivateDown)
|
|
|
|
overlay.off('mousedown', onActivate)
|
|
|
|
overlay.off('mousewheel', onActivate)
|
|
|
|
overlay.off('keydown keypress keyup click click dblclick mouseup mousewheel', preventDefault)
|
2021-09-13 04:41:10 +08:00
|
|
|
if (event instanceof KeyboardEvent == false && event.target && event.target.tagName === 'BUTTON') return;
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2020-09-15 20:14:14 +08:00
|
|
|
if (event instanceof WheelEvent) {
|
|
|
|
scope.key = 1001
|
|
|
|
} else {
|
|
|
|
scope.key = event.which
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
if (scope.ctrl !== null) scope.ctrl = event.ctrlKey
|
|
|
|
if (scope.shift !== null) scope.shift = event.shiftKey
|
|
|
|
if (scope.alt !== null) scope.alt = event.altKey
|
|
|
|
if (scope.meta !== null) scope.meta = event.metaKey
|
|
|
|
scope.label = scope.getText()
|
|
|
|
scope.save(true)
|
|
|
|
Blockbench.showQuickMessage(scope.label)
|
|
|
|
|
|
|
|
scope.stopRecording()
|
|
|
|
}
|
2021-01-17 04:43:36 +08:00
|
|
|
function onActivateDown(event) {
|
|
|
|
if (event.metaKey && event.which != 91) {
|
|
|
|
onActivate(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function preventDefault(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2021-01-17 04:43:36 +08:00
|
|
|
document.addEventListener('keyup', onActivate)
|
|
|
|
document.addEventListener('keydown', onActivateDown)
|
2019-07-18 00:02:07 +08:00
|
|
|
overlay.on('mousedown', onActivate)
|
2020-09-15 20:14:14 +08:00
|
|
|
overlay.on('mousewheel', onActivate)
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2021-01-17 04:43:36 +08:00
|
|
|
overlay.on('keydown keypress keyup click click dblclick mouseup mousewheel', preventDefault)
|
2019-07-18 00:02:07 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
stopRecording() {
|
|
|
|
Keybinds.recording = false
|
2020-09-15 20:14:14 +08:00
|
|
|
$('#overlay_message_box').hide().off('mousedown mousewheel')
|
2019-07-18 00:02:07 +08:00
|
|
|
$('#keybind_input_box').off('keyup keydown')
|
|
|
|
return this;
|
|
|
|
}
|
2020-10-15 04:50:10 +08:00
|
|
|
toString() {
|
|
|
|
return this.label
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2021-06-24 03:20:15 +08:00
|
|
|
Keybinds.loadKeymap = function(id, from_start_screen = false) {
|
|
|
|
let controls_only = from_start_screen && (id == 'default' || id == 'mouse');
|
|
|
|
let answer = controls_only || confirm(tl('message.load_keymap'));
|
2021-06-17 05:31:02 +08:00
|
|
|
if (!answer) return;
|
2023-02-01 06:48:29 +08:00
|
|
|
let preset = KeymapPresets[id] || {keys: {}};
|
2021-06-17 05:31:02 +08:00
|
|
|
|
2023-02-01 06:48:29 +08:00
|
|
|
if (!controls_only) {
|
|
|
|
function applyKeybinding(keys, keybind, default_keybind) {
|
|
|
|
if (keys) {
|
2021-09-02 04:13:04 +08:00
|
|
|
if (keys === null) {
|
2023-02-01 06:48:29 +08:00
|
|
|
keybind.clear();
|
2021-06-25 18:07:47 +08:00
|
|
|
} else if (keys) {
|
|
|
|
if (isApp && Blockbench.platform == 'darwin' && keys.ctrl && !keys.meta) {
|
|
|
|
keys.meta = true;
|
|
|
|
keys.ctrl = undefined;
|
|
|
|
}
|
|
|
|
if (typeof keys.key == 'string') {
|
|
|
|
keys.key = keys.key.toUpperCase().charCodeAt(0);
|
|
|
|
}
|
2023-02-01 06:48:29 +08:00
|
|
|
keybind.set(keys).save(false);
|
2021-06-24 03:20:15 +08:00
|
|
|
}
|
2021-06-17 05:31:02 +08:00
|
|
|
} else {
|
2023-02-01 06:48:29 +08:00
|
|
|
if (default_keybind) {
|
|
|
|
keybind.set(default_keybind);
|
2021-06-24 03:20:15 +08:00
|
|
|
} else {
|
2023-02-01 06:48:29 +08:00
|
|
|
keybind.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Keybinds.actions.forEach(item => {
|
|
|
|
if (!item.keybind) return;
|
|
|
|
|
|
|
|
applyKeybinding(preset.keys[item.id], item.keybind, item.default_keybind);
|
|
|
|
if (item.sub_keybinds) {
|
|
|
|
for (let key in item.sub_keybinds) {
|
|
|
|
applyKeybinding(
|
|
|
|
preset.keys[item.id + '.' + key],
|
|
|
|
item.sub_keybinds[key].keybind,
|
|
|
|
item.sub_keybinds[key].default_keybind
|
|
|
|
);
|
2021-06-24 03:20:15 +08:00
|
|
|
}
|
2021-06-17 05:31:02 +08:00
|
|
|
}
|
|
|
|
|
2021-06-24 03:20:15 +08:00
|
|
|
item.keybind.save(false);
|
|
|
|
})
|
2023-02-01 06:48:29 +08:00
|
|
|
}
|
2021-06-17 05:31:02 +08:00
|
|
|
|
|
|
|
if (id == 'mouse') {
|
|
|
|
Keybinds.extra.preview_rotate.keybind.set({key: 2}).save(false);
|
|
|
|
Keybinds.extra.preview_drag.keybind.set({key: 2, shift: true}).save(false);
|
|
|
|
Keybinds.extra.preview_zoom.keybind.set({key: 2, ctrl: true}).save(false);
|
2021-08-03 16:16:41 +08:00
|
|
|
Keybinds.extra.preview_area_select.keybind.set({key: 1}).save(false);
|
2021-06-17 05:31:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Keybinds.save();
|
|
|
|
TickUpdates.keybind_conflicts = true;
|
2021-06-24 03:20:15 +08:00
|
|
|
Blockbench.showQuickMessage('message.keymap_loaded', 1600);
|
2022-03-06 05:59:54 +08:00
|
|
|
return true;
|
2021-06-17 05:31:02 +08:00
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
Keybinds.no_overlap = function(k1, k2) {
|
2022-03-09 02:23:30 +08:00
|
|
|
return Condition.mutuallyExclusive(k1.condition, k2.condition);
|
2019-12-16 03:04:31 +08:00
|
|
|
}
|
|
|
|
function updateKeybindConflicts() {
|
|
|
|
for (var key in Keybinds.structure) {
|
|
|
|
Keybinds.structure[key].conflict = false;
|
|
|
|
}
|
|
|
|
Keybinds.actions.forEach((action, i) => {
|
|
|
|
action.keybind.conflict = false;
|
|
|
|
})
|
|
|
|
Keybinds.actions.forEach((action, i) => {
|
|
|
|
var keybind = action.keybind;
|
|
|
|
if (keybind.hasKey()) {
|
|
|
|
while (i < Keybinds.actions.length-1) {
|
|
|
|
i++;
|
|
|
|
var keybind2 = Keybinds.actions[i].keybind;
|
|
|
|
if (keybind2.hasKey()
|
|
|
|
&& keybind.key === keybind2.key
|
|
|
|
&& keybind.ctrl === keybind2.ctrl
|
|
|
|
&& keybind.shift === keybind2.shift
|
|
|
|
&& keybind.alt === keybind2.alt
|
|
|
|
&& keybind.meta === keybind2.meta
|
|
|
|
&& !Keybinds.no_overlap(action, Keybinds.actions[i])
|
|
|
|
) {
|
|
|
|
keybind.setConflict();
|
|
|
|
keybind2.setConflict();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-10-02 23:06:29 +08:00
|
|
|
if (Keybinds.dialog && Keybinds.dialog.sidebar.node) {
|
|
|
|
let node = Keybinds.dialog.sidebar.node;
|
|
|
|
for (var key in Keybinds.structure) {
|
2022-03-22 21:46:59 +08:00
|
|
|
if (Keybinds.dialog.sidebar.pages[key]) {
|
|
|
|
let page = node.querySelector(`.dialog_sidebar_pages li[page="${key}"]`)
|
|
|
|
page.classList.toggle('error', Keybinds.structure[key].conflict);
|
|
|
|
}
|
2021-10-02 23:06:29 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2021-04-26 01:40:15 +08:00
|
|
|
|
|
|
|
BARS.defineActions(() => {
|
|
|
|
|
2021-07-31 05:12:51 +08:00
|
|
|
new Action('keybindings_window', {
|
|
|
|
name: tl('dialog.settings.keybinds') + '...',
|
|
|
|
icon: 'keyboard',
|
|
|
|
category: 'blockbench',
|
|
|
|
click: function () {
|
|
|
|
Keybinds.dialog.show();
|
2021-09-08 15:55:06 +08:00
|
|
|
document.querySelector('dialog#keybindings .search_bar > input').focus();
|
2021-07-31 05:12:51 +08:00
|
|
|
}
|
|
|
|
})
|
2021-06-17 05:31:02 +08:00
|
|
|
new Action('load_keymap', {
|
|
|
|
icon: 'format_list_bulleted',
|
|
|
|
category: 'blockbench',
|
|
|
|
work_in_dialog: true,
|
|
|
|
click(e) {
|
|
|
|
new Menu(this.children).open(e.target);
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
'import_keymap',
|
|
|
|
'_',
|
2021-06-24 03:20:15 +08:00
|
|
|
{icon: 'keyboard', id: 'default', description: 'action.load_keymap.default.desc', name: 'action.load_keymap.default', click() {Keybinds.loadKeymap('default')}},
|
|
|
|
{icon: 'keyboard', id: 'mouse', description: 'action.load_keymap.mouse.desc', name: 'action.load_keymap.mouse', click() {Keybinds.loadKeymap('mouse')}},
|
|
|
|
{icon: 'keyboard', id: 'blender', description: 'action.load_keymap.blender.desc', name: 'Blender', click() {Keybinds.loadKeymap('blender')}},
|
|
|
|
{icon: 'keyboard', id: 'cinema4d', description: 'action.load_keymap.cinema4d.desc', name: 'Cinema 4D', click() {Keybinds.loadKeymap('cinema4d')}},
|
|
|
|
{icon: 'keyboard', id: 'maya', description: 'action.load_keymap.maya.desc', name: 'Maya', click() {Keybinds.loadKeymap('maya')}}
|
2021-06-17 05:31:02 +08:00
|
|
|
]
|
|
|
|
})
|
2021-04-26 01:40:15 +08:00
|
|
|
new Action('import_keymap', {
|
|
|
|
icon: 'folder',
|
|
|
|
category: 'blockbench',
|
2021-06-17 05:31:02 +08:00
|
|
|
work_in_dialog: true,
|
|
|
|
click() {
|
2021-04-26 01:40:15 +08:00
|
|
|
Blockbench.import({
|
|
|
|
resource_id: 'config',
|
|
|
|
extensions: ['bbkeymap'],
|
|
|
|
type: 'Blockbench Keymap'
|
|
|
|
}, function(files) {
|
|
|
|
let {keys} = JSON.parse(files[0].content);
|
|
|
|
|
|
|
|
Keybinds.actions.forEach(keybind_item => {
|
2021-09-02 04:13:04 +08:00
|
|
|
if (keys[keybind_item.id] === null) {
|
2021-04-26 01:40:15 +08:00
|
|
|
keybind_item.keybind.clear();
|
|
|
|
} else {
|
|
|
|
keybind_item.keybind.set(keys[keybind_item.id]).save(false);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Keybinds.save();
|
|
|
|
TickUpdates.keybind_conflicts = true;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('export_keymap', {
|
|
|
|
icon: 'keyboard_hide',
|
|
|
|
category: 'blockbench',
|
2021-06-17 05:31:02 +08:00
|
|
|
work_in_dialog: true,
|
|
|
|
click() {
|
2021-04-26 01:40:15 +08:00
|
|
|
var keys = {}
|
|
|
|
|
2021-06-25 00:19:06 +08:00
|
|
|
Keybinds.actions.forEach(item => {
|
2021-06-29 23:01:11 +08:00
|
|
|
if (!Keybinds.stored[item.id]) return
|
2021-06-25 00:19:06 +08:00
|
|
|
if (Keybinds.stored[item.id].key == -1) {
|
|
|
|
keys[item.id] = null;
|
2021-04-26 01:40:15 +08:00
|
|
|
} else {
|
2021-06-25 00:19:06 +08:00
|
|
|
keys[item.id] = new oneLiner(Keybinds.stored[item.id])
|
2021-04-26 01:40:15 +08:00
|
|
|
}
|
2021-06-25 00:19:06 +08:00
|
|
|
})
|
2021-04-26 01:40:15 +08:00
|
|
|
Blockbench.export({
|
|
|
|
resource_id: 'config',
|
|
|
|
type: 'Blockbench Keymap',
|
|
|
|
extensions: ['bbkeymap'],
|
|
|
|
content: compileJSON({keys})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2021-06-17 05:31:02 +08:00
|
|
|
BarItems.load_keymap.toElement('#keybinds_title_bar')
|
2021-04-26 01:40:15 +08:00
|
|
|
BarItems.export_keymap.toElement('#keybinds_title_bar')
|
|
|
|
})
|
|
|
|
|
2021-07-31 05:12:51 +08:00
|
|
|
onVueSetup(function() {
|
|
|
|
|
|
|
|
let sidebar_pages = {};
|
|
|
|
for (let key in Keybinds.structure) {
|
|
|
|
sidebar_pages[key] = Keybinds.structure[key].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Keybinds.dialog = new Dialog({
|
|
|
|
id: 'keybindings',
|
|
|
|
title: 'dialog.settings.keybinds',
|
|
|
|
singleButton: true,
|
2023-02-01 06:48:29 +08:00
|
|
|
width: 800,
|
2021-07-31 05:12:51 +08:00
|
|
|
title_menu: new Menu([
|
|
|
|
'settings_window',
|
|
|
|
'keybindings_window',
|
|
|
|
'theme_window',
|
|
|
|
'about_window',
|
|
|
|
]),
|
|
|
|
sidebar: {
|
|
|
|
pages: sidebar_pages,
|
|
|
|
page: 'navigate',
|
|
|
|
actions: [
|
|
|
|
'load_keymap',
|
|
|
|
'export_keymap',
|
|
|
|
],
|
|
|
|
onPageSwitch(page) {
|
|
|
|
Keybinds.dialog.content_vue.open_category = page;
|
|
|
|
Keybinds.dialog.content_vue.search_term = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
component: {
|
|
|
|
data() {return {
|
|
|
|
structure: Keybinds.structure,
|
|
|
|
open_category: 'navigate',
|
|
|
|
search_term: '',
|
|
|
|
}},
|
|
|
|
methods: {
|
2023-02-01 06:48:29 +08:00
|
|
|
record(item, sub_id) {
|
|
|
|
if (sub_id) {
|
|
|
|
item.sub_keybinds[sub_id].keybind.record();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!item.keybind) item.keybind = new Keybind();
|
|
|
|
item.keybind.record();
|
2021-07-31 05:12:51 +08:00
|
|
|
}
|
|
|
|
},
|
2023-02-01 06:48:29 +08:00
|
|
|
reset(item, sub_id) {
|
|
|
|
if (sub_id) {
|
|
|
|
let sub_keybind = item.sub_keybinds[sub_id];
|
|
|
|
if (sub_keybind.default_keybind) {
|
|
|
|
sub_keybind.keybind.set(sub_keybind.default_keybind);
|
|
|
|
} else {
|
|
|
|
sub_keybind.keybind.clear();
|
|
|
|
}
|
|
|
|
sub_keybind.keybind.save(true);
|
|
|
|
|
|
|
|
} else if (item.keybind) {
|
2021-07-31 05:12:51 +08:00
|
|
|
if (item.default_keybind) {
|
|
|
|
item.keybind.set(item.default_keybind);
|
|
|
|
} else {
|
|
|
|
item.keybind.clear();
|
|
|
|
}
|
|
|
|
item.keybind.save(true);
|
|
|
|
}
|
|
|
|
},
|
2023-02-01 06:48:29 +08:00
|
|
|
clear(item, sub_id) {
|
|
|
|
if (sub_id) {
|
|
|
|
item.sub_keybinds[sub_id].keybind.clear().save(true);
|
|
|
|
|
|
|
|
} else if (item.keybind) {
|
2021-07-31 05:12:51 +08:00
|
|
|
item.keybind.clear().save(true)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleCategory(category) {
|
|
|
|
if (!category.open) {
|
|
|
|
for (var ct in Keybinds.structure) {
|
|
|
|
Keybinds.structure[ct].open = false
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
category.open = !category.open
|
2023-02-01 06:48:29 +08:00
|
|
|
},
|
|
|
|
hasSubKeybinds(item) {
|
|
|
|
return item.sub_keybinds && typeof item.sub_keybinds === 'object' && Object.keys(item.sub_keybinds).length > 0;
|
2021-07-31 05:12:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
list() {
|
|
|
|
if (this.search_term) {
|
2022-05-20 04:48:41 +08:00
|
|
|
var keywords = this.search_term.toLowerCase().replace(/_/g, ' ').split(' ');
|
2021-07-31 05:12:51 +08:00
|
|
|
var actions = [];
|
|
|
|
|
|
|
|
for (var action of Keybinds.actions) {
|
|
|
|
|
|
|
|
if (true) {;
|
|
|
|
var missmatch = false;
|
|
|
|
for (var word of keywords) {
|
|
|
|
if (
|
2023-04-06 03:32:08 +08:00
|
|
|
!missmatch &&
|
2021-07-31 05:12:51 +08:00
|
|
|
!action.name.toLowerCase().includes(word) &&
|
|
|
|
!action.id.toLowerCase().includes(word) &&
|
2023-04-06 03:32:08 +08:00
|
|
|
!action.keybind.label.toLowerCase().includes(word)
|
2021-07-31 05:12:51 +08:00
|
|
|
) {
|
|
|
|
missmatch = true;
|
|
|
|
}
|
2023-04-06 03:32:08 +08:00
|
|
|
if (missmatch && action.sub_keybinds) {
|
|
|
|
for (let key in action.sub_keybinds) {
|
|
|
|
if (action.sub_keybinds[key].name.toLowerCase().includes(word)) {
|
|
|
|
missmatch = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (missmatch) break;
|
2021-07-31 05:12:51 +08:00
|
|
|
}
|
|
|
|
if (!missmatch) {
|
|
|
|
actions.push(action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actions;
|
|
|
|
} else {
|
|
|
|
return this.structure[this.open_category].actions;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
if (this.search_term) {
|
|
|
|
return tl('dialog.settings.search_results');
|
|
|
|
} else {
|
|
|
|
return this.structure[this.open_category].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<h2 class="i_b">{{ title }}</h2>
|
|
|
|
|
|
|
|
<search-bar id="settings_search_bar" v-model="search_term"></search-bar>
|
|
|
|
|
|
|
|
<ul id="keybindlist">
|
|
|
|
<li v-for="action in list">
|
2023-02-01 06:48:29 +08:00
|
|
|
<div class="keybind_line">
|
|
|
|
<div :title="action.description"><span>{{action.name}}</span><span class="keybind_guide_line" /></div>
|
|
|
|
<div class="keybindslot" :class="{conflict: action.keybind && action.keybind.conflict}" @click.stop="record(action)" v-html="action.keybind ? action.keybind.getText(true) : ''"></div>
|
|
|
|
|
|
|
|
<div class="tool" v-on:click="reset(action)" title="${tl('keybindings.reset')}"><i class="material-icons">replay</i></div>
|
|
|
|
<div class="tool" v-on:click="clear(action)" title="${tl('keybindings.clear')}"><i class="material-icons">clear</i></div>
|
2021-07-31 05:12:51 +08:00
|
|
|
</div>
|
2023-02-01 06:48:29 +08:00
|
|
|
|
|
|
|
<ul class="keybind_item_sub_keybinds" v-if="hasSubKeybinds(action)">
|
|
|
|
<li v-for="(sub_keybind, sub_id) in action.sub_keybinds" class="keybind_line keybind_line__sub" :key="sub_id">
|
|
|
|
<div><span>{{ sub_keybind.name }}</span><span class="keybind_guide_line" /></div>
|
|
|
|
<div class="keybindslot"
|
|
|
|
:class="{conflict: sub_keybind.keybind && sub_keybind.keybind.conflict}"
|
|
|
|
@click.stop="record(action, sub_id)"
|
|
|
|
v-html="sub_keybind.keybind ? sub_keybind.keybind.getText(true) : ''"
|
|
|
|
></div>
|
|
|
|
|
|
|
|
<div class="tool" v-on:click="reset(action, sub_id)" title="${tl('keybindings.reset')}"><i class="material-icons">replay</i></div>
|
|
|
|
<div class="tool" v-on:click="clear(action, sub_id)" title="${tl('keybindings.clear')}"><i class="material-icons">clear</i></div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2021-07-31 05:12:51 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>`
|
|
|
|
},
|
|
|
|
onButton() {
|
|
|
|
Settings.save();
|
2022-06-10 23:55:13 +08:00
|
|
|
},
|
|
|
|
onOpen() {
|
|
|
|
updateKeybindConflicts();
|
2021-07-31 05:12:51 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2021-04-26 01:40:15 +08:00
|
|
|
|
2020-09-01 03:56:15 +08:00
|
|
|
window.addEventListener('blur', event => {
|
|
|
|
if (Pressing.alt) {
|
2019-09-04 15:37:38 +08:00
|
|
|
if (Toolbox.original && Toolbox.original.alt_tool) {
|
|
|
|
Toolbox.original.select()
|
|
|
|
delete Toolbox.original;
|
|
|
|
}
|
|
|
|
}
|
2020-09-01 03:56:15 +08:00
|
|
|
Pressing.shift = false;
|
|
|
|
Pressing.alt = false;
|
|
|
|
Pressing.ctrl = false;
|
|
|
|
})
|
|
|
|
|
|
|
|
window.addEventListener('focus', event => {
|
|
|
|
function click_func(event) {
|
|
|
|
if (event.altKey && Toolbox.selected.alt_tool && !Toolbox.original && !open_interface) {
|
|
|
|
var orig = Toolbox.selected;
|
|
|
|
var alt = BarItems[Toolbox.selected.alt_tool];
|
2021-07-02 03:05:02 +08:00
|
|
|
if (alt && Condition(alt) && (Modes.paint || BarItems.swap_tools.keybind.key == 18)) {
|
2020-09-01 03:56:15 +08:00
|
|
|
alt.select()
|
|
|
|
Toolbox.original = orig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remove_func();
|
|
|
|
}
|
|
|
|
let removed = false
|
|
|
|
function remove_func() {
|
|
|
|
if (removed) return;
|
|
|
|
removed = true;
|
|
|
|
removeEventListeners(window, 'keydown mousedown', click_func, true);
|
|
|
|
}
|
|
|
|
addEventListeners(window, 'keydown mousedown', click_func, true);
|
|
|
|
setTimeout(remove_func, 100);
|
|
|
|
})
|
2019-09-04 15:37:38 +08:00
|
|
|
|
2020-10-17 21:17:27 +08:00
|
|
|
function getFocusedTextInput() {
|
2022-04-22 01:22:05 +08:00
|
|
|
let element = document.activeElement;
|
|
|
|
if (element.nodeName == 'TEXTAREA' || (element.nodeName == 'INPUT' && ['number', 'text'].includes(element.type)) || element.isContentEditable) {
|
|
|
|
return element;
|
|
|
|
}
|
2020-09-15 20:14:14 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 03:29:09 +08:00
|
|
|
addEventListeners(document, 'keydown mousedown', function(e) {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (Keybinds.recording || e.which < 4) return;
|
|
|
|
//Shift
|
|
|
|
Pressing.shift = e.shiftKey;
|
|
|
|
Pressing.alt = e.altKey;
|
|
|
|
Pressing.ctrl = e.ctrlKey;
|
|
|
|
if (e.which === 16) {
|
|
|
|
showShiftTooltip()
|
|
|
|
}
|
|
|
|
|
|
|
|
var used = false;
|
2020-10-17 21:17:27 +08:00
|
|
|
var input_focus = getFocusedTextInput()
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2022-08-25 01:09:36 +08:00
|
|
|
// Fix #1427
|
|
|
|
if (e.code == 'PageUp' || e.code == 'PageDown') {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
if (input_focus) {
|
|
|
|
//User Editing Anything
|
2020-09-14 00:31:46 +08:00
|
|
|
|
|
|
|
//Tab
|
2023-04-14 00:15:55 +08:00
|
|
|
if (e.which == 9 && !open_dialog && !document.querySelector('.capture_tab_key:focus-within')) {
|
2022-05-20 02:49:26 +08:00
|
|
|
let all_visible_inputs = [];
|
2022-12-17 09:00:18 +08:00
|
|
|
var all_inputs = document.querySelectorAll('.tab_target:not(.prism-editor-component), .prism-editor-component.tab_target > .prism-editor-wrapper > pre[contenteditable="true"]')
|
2022-05-20 02:49:26 +08:00
|
|
|
all_inputs.forEach(input => {
|
|
|
|
if (input.isConnected && input.offsetParent && $(input).is(':visible')) {
|
|
|
|
all_visible_inputs.push(input);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
var index = all_visible_inputs.indexOf(input_focus)+1;
|
|
|
|
if (index >= all_visible_inputs.length) index = 0;
|
|
|
|
var next = $(all_visible_inputs[index])
|
2020-09-14 00:31:46 +08:00
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
if (next.length) {
|
|
|
|
if (next.hasClass('cube_name')) {
|
2020-12-31 22:08:35 +08:00
|
|
|
let uuid = next.parent().parent().attr('id');
|
2021-01-31 05:41:24 +08:00
|
|
|
var target = OutlinerNode.uuids[uuid];
|
2019-12-16 03:04:31 +08:00
|
|
|
if (target) {
|
|
|
|
stopRenameOutliner();
|
|
|
|
setTimeout(() => {
|
|
|
|
target.select(e, true).rename();
|
|
|
|
}, 50)
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (next.hasClass('nslide')) {
|
2023-01-21 00:59:56 +08:00
|
|
|
let n_action = next.attr('n-action');
|
|
|
|
let slider = BarItems[n_action] || UVEditor.sliders[n_action.replace('uv_slider_', '')];
|
|
|
|
if (slider) {
|
|
|
|
setTimeout(() => slider.startInput(e), 50);
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
} else {
|
2020-12-06 06:56:57 +08:00
|
|
|
event.preventDefault();
|
2021-02-27 22:38:49 +08:00
|
|
|
next.trigger('focus').trigger('click');
|
|
|
|
document.execCommand('selectAll')
|
2019-12-16 03:04:31 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 05:44:06 +08:00
|
|
|
if (Blockbench.hasFlag('renaming')) {
|
|
|
|
if (Keybinds.extra.confirm.keybind.isTriggered(e)) {
|
|
|
|
stopRenameOutliner()
|
|
|
|
} else if (Keybinds.extra.cancel.keybind.isTriggered(e)) {
|
|
|
|
stopRenameOutliner(false)
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-07-24 19:51:42 +08:00
|
|
|
if ($('input#chat_input:focus').length && Project.EditSession) {
|
2020-10-05 05:44:06 +08:00
|
|
|
if (Keybinds.extra.confirm.keybind.isTriggered(e)) {
|
2021-07-24 19:51:42 +08:00
|
|
|
Interface.Panels.chat.inside_vue.sendMessage();
|
2020-10-05 05:44:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($('pre.prism-editor__code:focus').length) return;
|
2019-07-18 00:02:07 +08:00
|
|
|
if (Keybinds.extra.confirm.keybind.isTriggered(e) || Keybinds.extra.cancel.keybind.isTriggered(e)) {
|
2020-12-06 06:56:57 +08:00
|
|
|
$(document).trigger('click')
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
2021-06-23 03:29:09 +08:00
|
|
|
let captured = false;
|
|
|
|
let results = Blockbench.dispatchEvent('press_key', {
|
|
|
|
input_in_focus: input_focus,
|
|
|
|
event: e,
|
|
|
|
capture() {
|
|
|
|
captured = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (results instanceof Array && results.includes(true)) used = true;
|
|
|
|
if (captured) {
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
//Hardcoded Keys
|
2020-10-18 03:54:08 +08:00
|
|
|
if (e.which === 18 && Toolbox.selected.alt_tool && !Toolbox.original && !open_interface) {
|
2019-07-18 00:02:07 +08:00
|
|
|
//Alt Tool
|
|
|
|
var orig = Toolbox.selected;
|
|
|
|
var alt = BarItems[Toolbox.selected.alt_tool]
|
2021-07-02 03:05:02 +08:00
|
|
|
if (alt && Condition(alt) && (Modes.paint || BarItems.swap_tools.keybind.key == 18)) {
|
2021-12-12 20:26:23 +08:00
|
|
|
e.preventDefault();
|
2019-07-18 00:02:07 +08:00
|
|
|
alt.select()
|
|
|
|
Toolbox.original = orig
|
|
|
|
}
|
2021-06-06 15:52:17 +08:00
|
|
|
} else if (Keybinds.extra.cancel.keybind.isTriggered(e) && (Transformer.dragging)) {
|
|
|
|
Transformer.cancelMovement(e, false);
|
2021-06-12 23:20:36 +08:00
|
|
|
updateSelection();
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
//Keybinds
|
|
|
|
if (!input_focus) {
|
|
|
|
Keybinds.actions.forEach(function(action) {
|
2023-02-01 06:48:29 +08:00
|
|
|
if (!open_dialog || action.work_in_dialog) {
|
|
|
|
// Condition for actions is not checked here because tools can be triggered from different modes under certain circumstances, which switches the mode
|
|
|
|
if (action.keybind && typeof action.trigger === 'function' && action.keybind.isTriggered(e)) {
|
|
|
|
if (action.trigger(e)) used = true
|
|
|
|
}
|
|
|
|
if (action.sub_keybinds && Condition(action.condition)) {
|
|
|
|
for (let sub_id in action.sub_keybinds) {
|
|
|
|
let sub = action.sub_keybinds[sub_id];
|
|
|
|
if (sub.keybind.isTriggered(e)) {
|
|
|
|
sub.trigger(e)
|
|
|
|
used = true;
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-02-05 02:48:32 +08:00
|
|
|
// Menu
|
|
|
|
if (open_menu) {
|
|
|
|
used = open_menu.keyNavigate(e)||used
|
|
|
|
|
|
|
|
// Dialog
|
|
|
|
} else if (Dialog.open) {
|
2019-07-18 00:02:07 +08:00
|
|
|
if ($('textarea:focus').length === 0) {
|
|
|
|
if (Keybinds.extra.confirm.keybind.isTriggered(e)) {
|
2023-02-18 16:30:40 +08:00
|
|
|
if (input_focus) {
|
|
|
|
input_focus.blur();
|
|
|
|
}
|
2023-02-05 02:48:32 +08:00
|
|
|
Dialog.open.confirm(e);
|
2019-07-18 00:02:07 +08:00
|
|
|
used = true
|
|
|
|
} else if (Keybinds.extra.cancel.keybind.isTriggered(e)) {
|
2023-02-05 02:48:32 +08:00
|
|
|
Dialog.open.cancel(e);
|
2019-07-18 00:02:07 +08:00
|
|
|
used = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (open_interface && typeof open_interface == 'object' && open_interface.hide) {
|
|
|
|
if (Keybinds.extra.confirm.keybind.isTriggered(e)) {
|
|
|
|
open_interface.confirm(e)
|
|
|
|
used = true
|
|
|
|
} else if (Keybinds.extra.cancel.keybind.isTriggered(e)) {
|
|
|
|
open_interface.hide(e)
|
|
|
|
used = true
|
|
|
|
}
|
2023-02-20 00:56:08 +08:00
|
|
|
} else if (ReferenceImageMode.active) {
|
|
|
|
if (Keybinds.extra.confirm.keybind.isTriggered(e) || Keybinds.extra.cancel.keybind.isTriggered(e)) {
|
|
|
|
ReferenceImageMode.deactivate();
|
|
|
|
used = true;
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
if (ActionControl.open) {
|
|
|
|
used = ActionControl.handleKeys(e) || used
|
|
|
|
}
|
|
|
|
if (used) {
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
|
|
|
})
|
2020-09-15 20:14:14 +08:00
|
|
|
document.addEventListener('wheel', (e) => {
|
2020-10-17 21:17:27 +08:00
|
|
|
if (getFocusedTextInput()) return;
|
2020-09-15 20:14:14 +08:00
|
|
|
let used = false;
|
|
|
|
Keybinds.actions.forEach(function(action) {
|
|
|
|
if (
|
|
|
|
action.keybind &&
|
|
|
|
(!open_dialog || action.work_in_dialog) &&
|
|
|
|
typeof action.trigger === 'function' &&
|
|
|
|
action.keybind.isTriggered(e)
|
|
|
|
) {
|
|
|
|
if (action.trigger(e)) {
|
|
|
|
used = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (used) {
|
|
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
|
|
|
|
}, true)
|
2019-07-18 00:02:07 +08:00
|
|
|
|
|
|
|
$(document).keyup(function(e) {
|
|
|
|
if (Pressing.alt && ActionControl.open) {
|
|
|
|
ActionControl.vue.$forceUpdate()
|
|
|
|
}
|
|
|
|
if (e.which === 18 && Toolbox.original && Toolbox.original.alt_tool) {
|
|
|
|
Toolbox.original.select()
|
|
|
|
delete Toolbox.original;
|
|
|
|
}
|
|
|
|
Pressing.shift = false;
|
|
|
|
Pressing.alt = false;
|
|
|
|
Pressing.ctrl = false;
|
|
|
|
})
|