mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 22:10:22 +00:00
Bind formatting hotkeys on input element
And bind only one event for all of the hotkeys
This commit is contained in:
parent
453eab3a12
commit
3c1db1d7d6
1 changed files with 6 additions and 12 deletions
|
@ -95,6 +95,7 @@ Mousetrap.bind([
|
||||||
contextMenuContainer.hide();
|
contextMenuContainer.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const inputTrap = Mousetrap(input.get(0));
|
||||||
const colorsHotkeys = {
|
const colorsHotkeys = {
|
||||||
k: "\x03",
|
k: "\x03",
|
||||||
b: "\x02",
|
b: "\x02",
|
||||||
|
@ -106,23 +107,16 @@ const colorsHotkeys = {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const hotkey in colorsHotkeys) {
|
for (const hotkey in colorsHotkeys) {
|
||||||
Mousetrap.bind("mod+" + hotkey, function(e) {
|
inputTrap.bind("mod+" + hotkey, function(e) {
|
||||||
const inputElement = input.get(0);
|
|
||||||
|
|
||||||
// Do not handle modifier hotkeys if input is not focused
|
|
||||||
if (document.activeElement !== inputElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
const modifier = colorsHotkeys[e.key];
|
const modifier = colorsHotkeys[e.key];
|
||||||
|
|
||||||
wrapCursor(
|
wrapCursor(
|
||||||
inputElement,
|
e.target,
|
||||||
modifier,
|
modifier,
|
||||||
inputElement.selectionStart === inputElement.selectionEnd ? "" : modifier
|
e.target.selectionStart === e.target.selectionEnd ? "" : modifier
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue