From b7d5602ccefeeea8f82b2be14f365512415da616 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins <matiss@mja.lv> Date: Mon, 26 Jun 2023 17:19:11 +0100 Subject: [PATCH] :arrow_up: upgrade hotkeys-js from v3.8.2 to v3.10.3, remove monkeypatch (#1195) --- packages/desktop-client/package.json | 2 +- .../src/components/accounts/Account.js | 2 +- patches/hotkeys-js+3.8.2.patch | 94 ------------------- upcoming-release-notes/1195.md | 6 ++ yarn.lock | 10 +- 5 files changed, 13 insertions(+), 101 deletions(-) delete mode 100644 patches/hotkeys-js+3.8.2.patch create mode 100644 upcoming-release-notes/1195.md diff --git a/packages/desktop-client/package.json b/packages/desktop-client/package.json index df730fce1..e6bf34b0b 100644 --- a/packages/desktop-client/package.json +++ b/packages/desktop-client/package.json @@ -31,7 +31,7 @@ "focus-visible": "^4.1.1", "formik": "^0.11.10", "glamor": "^2.20.40", - "hotkeys-js": "3.8.2", + "hotkeys-js": "3.10.3", "identity-obj-proxy": "3.0.0", "inter-ui": "^3.19.3", "jest": "^27.0.0", diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.js index 296af367f..c94190e64 100644 --- a/packages/desktop-client/src/components/accounts/Account.js +++ b/packages/desktop-client/src/components/accounts/Account.js @@ -735,7 +735,7 @@ const AccountHeader = memo( <> <KeyHandlers keys={{ - 'mod+f': () => { + 'ctrl+f, cmd+f': () => { if (searchInput.current) { searchInput.current.focus(); } diff --git a/patches/hotkeys-js+3.8.2.patch b/patches/hotkeys-js+3.8.2.patch deleted file mode 100644 index 59831a3c9..000000000 --- a/patches/hotkeys-js+3.8.2.patch +++ /dev/null @@ -1,94 +0,0 @@ -diff --git a/node_modules/hotkeys-js/dist/hotkeys.common.js b/node_modules/hotkeys-js/dist/hotkeys.common.js -index bc18534..34c0d7d 100644 ---- a/node_modules/hotkeys-js/dist/hotkeys.common.js -+++ b/node_modules/hotkeys-js/dist/hotkeys.common.js -@@ -22,7 +22,6 @@ function addEvent(object, event, method) { - } - } // 修饰键转æ¢æˆå¯¹åº”çš„é”®ç - -- - function getMods(modifier, key) { - var mods = key.slice(0, key.length - 1); - -@@ -33,7 +32,6 @@ function getMods(modifier, key) { - return mods; - } // 处ç†ä¼ çš„keyå—符串转æ¢æˆæ•°ç»„ - -- - function getKeys(key) { - if (typeof key !== 'string') key = ''; - key = key.replace(/\s/g, ''); // 匹é…任何空白å—符,åŒ…æ‹¬ç©ºæ ¼ã€åˆ¶è¡¨ç¬¦ã€æ¢é¡µç¬¦ç‰ç‰ -diff --git a/node_modules/hotkeys-js/dist/hotkeys.esm.js b/node_modules/hotkeys-js/dist/hotkeys.esm.js -index 90295a5..f998483 100644 ---- a/node_modules/hotkeys-js/dist/hotkeys.esm.js -+++ b/node_modules/hotkeys-js/dist/hotkeys.esm.js -@@ -9,6 +9,8 @@ - */ - - var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; // 绑定事件 -+var ismac = -+ navigator.platform && navigator.platform.toUpperCase().indexOf('MAC') >= 0; - - function addEvent(object, event, method) { - if (object.addEventListener) { -@@ -20,12 +22,20 @@ function addEvent(object, event, method) { - } - } // 修饰键转æ¢æˆå¯¹åº”çš„é”®ç - -- - function getMods(modifier, key) { - var mods = key.slice(0, key.length - 1); - - for (var i = 0; i < mods.length; i++) { -- mods[i] = modifier[mods[i].toLowerCase()]; -+ let mod = mods[i].toLowerCase(); -+ if(mod === 'mod') { -+ if(ismac) { -+ mod = 'cmd'; -+ } -+ else { -+ mod = 'ctrl'; -+ } -+ } -+ mods[i] = modifier[mod]; - } - - return mods; -@@ -145,6 +155,9 @@ var elementHasBindEvent = []; // 已绑定事件的节点记录 - // 返回键ç - - var code = function code(x) { -+ if(x === 'mod') { -+ x = ismac ? 'cmd' : 'ctrl' -+ } - return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); - }; // 设置获å–当å‰èŒƒå›´ï¼ˆé»˜è®¤ä¸º'所有') - -@@ -319,7 +332,6 @@ function eventHandler(event, handler, scope) { - } - } // 调用处ç†ç¨‹åºï¼Œå¦‚果是修饰键ä¸åšå¤„ç† - -- - if (handler.mods.length === 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91] || modifiersMatch || handler.shortcut === '*') { - if (handler.method(event, handler) === false) { - if (event.preventDefault) event.preventDefault();else event.returnValue = false; -diff --git a/node_modules/hotkeys-js/dist/hotkeys.js b/node_modules/hotkeys-js/dist/hotkeys.js -index 15480e8..d203a42 100644 ---- a/node_modules/hotkeys-js/dist/hotkeys.js -+++ b/node_modules/hotkeys-js/dist/hotkeys.js -@@ -26,7 +26,6 @@ - } - } // 修饰键转æ¢æˆå¯¹åº”çš„é”®ç - -- - function getMods(modifier, key) { - var mods = key.slice(0, key.length - 1); - -@@ -37,7 +36,6 @@ - return mods; - } // 处ç†ä¼ çš„keyå—符串转æ¢æˆæ•°ç»„ - -- - function getKeys(key) { - if (typeof key !== 'string') key = ''; - key = key.replace(/\s/g, ''); // 匹é…任何空白å—符,åŒ…æ‹¬ç©ºæ ¼ã€åˆ¶è¡¨ç¬¦ã€æ¢é¡µç¬¦ç‰ç‰ diff --git a/upcoming-release-notes/1195.md b/upcoming-release-notes/1195.md new file mode 100644 index 000000000..4aca868c0 --- /dev/null +++ b/upcoming-release-notes/1195.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MatissJanis] +--- + +Upgrade `hotkeys-js` and remove monkeypatch diff --git a/yarn.lock b/yarn.lock index ccf33b1e5..0cedf12f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -94,7 +94,7 @@ __metadata: focus-visible: ^4.1.1 formik: ^0.11.10 glamor: ^2.20.40 - hotkeys-js: 3.8.2 + hotkeys-js: 3.10.3 identity-obj-proxy: 3.0.0 inter-ui: ^3.19.3 jest: ^27.0.0 @@ -10002,10 +10002,10 @@ __metadata: languageName: node linkType: hard -"hotkeys-js@npm:3.8.2": - version: 3.8.2 - resolution: "hotkeys-js@npm:3.8.2" - checksum: 0fbe8e4a1b3091b9bb1ed2ca220509bda5337a0ab6a90b963ee2a942e06aef25eb4294ca7048f30a00be41f14002691e153c17797a4c0604fde71011318bb05f +"hotkeys-js@npm:3.10.3": + version: 3.10.3 + resolution: "hotkeys-js@npm:3.10.3" + checksum: c88bbb1178e61a0e52129a22ef4083c2f40de6d57041df1b18baa376424726073d122423ee125dfb92fdc5811ef1c0cd5e0bb394fc9f5a012a84653fd17dc76f languageName: node linkType: hard -- GitLab