Merge pull request #2242 from thelounge/xpaw/fix-master

Keep input reference as jquery object
This commit is contained in:
Pavel Djundik 2018-03-16 18:56:34 +02:00 committed by GitHub
commit 0858938eea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@
const $ = require("jquery"); const $ = require("jquery");
const Mousetrap = require("mousetrap"); const Mousetrap = require("mousetrap");
const wrapCursor = require("undate").wrapCursor; const wrapCursor = require("undate").wrapCursor;
const input = $("#input").get(0); const input = $("#input");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
const windows = $("#windows"); const windows = $("#windows");
const contextMenuContainer = $("#context-menu-container"); const contextMenuContainer = $("#context-menu-container");
@ -107,8 +107,10 @@ const colorsHotkeys = {
for (const hotkey in colorsHotkeys) { for (const hotkey in colorsHotkeys) {
Mousetrap.bind("mod+" + hotkey, function(e) { Mousetrap.bind("mod+" + hotkey, function(e) {
const inputElement = input.get(0);
// Do not handle modifier hotkeys if input is not focused // Do not handle modifier hotkeys if input is not focused
if (document.activeElement !== input) { if (document.activeElement !== inputElement) {
return; return;
} }
@ -116,7 +118,11 @@ for (const hotkey in colorsHotkeys) {
const modifier = colorsHotkeys[e.key]; const modifier = colorsHotkeys[e.key];
wrapCursor(input, modifier, input.selectionStart === input.selectionEnd ? "" : modifier); wrapCursor(
inputElement,
modifier,
inputElement.selectionStart === inputElement.selectionEnd ? "" : modifier
);
}); });
} }