From b3e46eec62ab8ed00e3d15e1b5bdaeb3d330331f Mon Sep 17 00:00:00 2001 From: tsym77yoshi <67378554+tsym77yoshi@users.noreply.github.com> Date: Sat, 30 Mar 2024 01:10:06 +0900 Subject: [PATCH 1/7] =?UTF-8?q?FIX:=20=E3=83=9B=E3=83=83=E3=83=88=E3=82=AD?= =?UTF-8?q?=E3=83=BC=E3=81=A7shift+=E6=95=B0=E5=AD=97=E3=82=92=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E6=99=82=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit event.code式に書き換え .がPeriodだったりと様々な対応しきれないものがあるので対応しているもの以外は弾くようにした --- src/plugins/hotkeyPlugin.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index 2efb55295c..a9cc8d1930 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -311,15 +311,18 @@ export const eventToCombination = (event: KeyboardEvent): HotkeyCombination => { if (event.metaKey) { recordedCombination += "Meta "; } - if (event.key === " ") { - recordedCombination += "Space"; - } else { - if (["Control", "Shift", "Alt", "Meta"].includes(event.key)) { - recordedCombination = recordedCombination.slice(0, -1); - } else { - recordedCombination += - event.key.length > 1 ? event.key : event.key.toUpperCase(); - } + // event.codeから保存する形へと変換 + let eventKey = event.code.replace(/Key|Digit|Numpad|Arrow/, ""); + eventKey = eventKey.length > 1 ? eventKey : eventKey.toUpperCase(); + // 英字 数字 上下左右 Enter Space Backspace Delete Escape F1~のみ認める + if ( + /^([A-Z]|\d|Up|Down|Left|Right|Enter|Space|Backspace|Delete|Escape|F\d+)$/.test( + eventKey + ) + ) { + recordedCombination += eventKey; } + // 末尾がスペースならそれを削除 + recordedCombination = recordedCombination.replace(/\s$/, ""); return HotkeyCombination(recordedCombination); }; From c0508ac952444d3456e65ba77b84513aa4edc52b Mon Sep 17 00:00:00 2001 From: tsym77yoshi <67378554+tsym77yoshi@users.noreply.github.com> Date: Mon, 6 May 2024 00:38:30 +0900 Subject: [PATCH 2/7] =?UTF-8?q?Update:=20=E3=81=A8=E3=82=8A=E3=81=82?= =?UTF-8?q?=E3=81=88=E3=81=9A=E6=97=A2=E5=AD=98=E3=81=AE=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F=E3=81=AE=E3=81=BE=E3=81=BE=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=80=81-=E3=81=A8/=E3=82=82=E8=AA=8D=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/hotkeyPlugin.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index a9cc8d1930..95bda9be08 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -279,10 +279,12 @@ const combinationToBindingKey = ( // MetaキーはCommandキーとして扱う // NOTE: hotkeys-jsにはWinキーが無く、Commandキーとして扱われている // NOTE: Metaキーは以前採用していたmousetrapがそうだった名残り + // hotkeys-jsでは方向キーをup, down, left, rightで表す const bindingKey = combination .toLowerCase() .split(" ") .map((key) => (key === "meta" ? "command" : key)) + .map((key) => key.replace("arrow", "")) .join("+"); return bindingKey as BindingKey; }; @@ -311,12 +313,15 @@ export const eventToCombination = (event: KeyboardEvent): HotkeyCombination => { if (event.metaKey) { recordedCombination += "Meta "; } - // event.codeから保存する形へと変換 - let eventKey = event.code.replace(/Key|Digit|Numpad|Arrow/, ""); - eventKey = eventKey.length > 1 ? eventKey : eventKey.toUpperCase(); - // 英字 数字 上下左右 Enter Space Backspace Delete Escape F1~のみ認める + // event.codeから以前のevent.key形式へと変換 + // 列挙するのは将来的に変更する + let eventKey = event.code + .replace(/Key|Digit|Numpad/, "") + .replace("Minus", "-") + .replace("Slash", "/"); + // 英字 数字 上下左右 Enter Space Backspace Delete Escape F1~ - /のみ認める if ( - /^([A-Z]|\d|Up|Down|Left|Right|Enter|Space|Backspace|Delete|Escape|F\d+)$/.test( + /^([A-Z]|\d|Arrow(Up|Down|Left|Right)|Enter|Space|Backspace|Delete|Escape|F\d+|-|\/)$/.test( eventKey ) ) { From 2292a58ef785075fa3a659d6313cabf3268d4006 Mon Sep 17 00:00:00 2001 From: tsym77yoshi <67378554+tsym77yoshi@users.noreply.github.com> Date: Mon, 6 May 2024 00:42:28 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20lint=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/hotkeyPlugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index 95bda9be08..e623147f1c 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -315,14 +315,14 @@ export const eventToCombination = (event: KeyboardEvent): HotkeyCombination => { } // event.codeから以前のevent.key形式へと変換 // 列挙するのは将来的に変更する - let eventKey = event.code + const eventKey = event.code .replace(/Key|Digit|Numpad/, "") .replace("Minus", "-") .replace("Slash", "/"); // 英字 数字 上下左右 Enter Space Backspace Delete Escape F1~ - /のみ認める if ( /^([A-Z]|\d|Arrow(Up|Down|Left|Right)|Enter|Space|Backspace|Delete|Escape|F\d+|-|\/)$/.test( - eventKey + eventKey, ) ) { recordedCombination += eventKey; From 1669c4c8b6b5f379d0cfcc3003c3f5a71ee193f1 Mon Sep 17 00:00:00 2001 From: tsym <67378554+tsym77yoshi@users.noreply.github.com> Date: Sun, 12 May 2024 12:27:18 +0900 Subject: [PATCH 4/7] Update src/plugins/hotkeyPlugin.ts Co-authored-by: Hiroshiba --- src/plugins/hotkeyPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index e623147f1c..8762fc7394 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -279,7 +279,7 @@ const combinationToBindingKey = ( // MetaキーはCommandキーとして扱う // NOTE: hotkeys-jsにはWinキーが無く、Commandキーとして扱われている // NOTE: Metaキーは以前採用していたmousetrapがそうだった名残り - // hotkeys-jsでは方向キーをup, down, left, rightで表す + // NOTE: hotkeys-jsでは方向キーのarrowプレフィックスが不要 const bindingKey = combination .toLowerCase() .split(" ") From 9ba0ec5de41b3367adea134a0ce69766137b80aa Mon Sep 17 00:00:00 2001 From: tsym <67378554+tsym77yoshi@users.noreply.github.com> Date: Sun, 12 May 2024 12:27:40 +0900 Subject: [PATCH 5/7] Update src/plugins/hotkeyPlugin.ts Co-authored-by: Hiroshiba --- src/plugins/hotkeyPlugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index 8762fc7394..5690be53ab 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -313,8 +313,8 @@ export const eventToCombination = (event: KeyboardEvent): HotkeyCombination => { if (event.metaKey) { recordedCombination += "Meta "; } - // event.codeから以前のevent.key形式へと変換 - // 列挙するのは将来的に変更する + // event.codeからevent.key形式へと変換 + // TODO: 主要なキーも使えるようにする const eventKey = event.code .replace(/Key|Digit|Numpad/, "") .replace("Minus", "-") From e3f95e2a33edbb8bf6d8ef855aeef6b4bd2942ba Mon Sep 17 00:00:00 2001 From: tsym <67378554+tsym77yoshi@users.noreply.github.com> Date: Sun, 12 May 2024 12:29:46 +0900 Subject: [PATCH 6/7] Update hotkeyPlugin.ts --- src/plugins/hotkeyPlugin.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index 5690be53ab..816bb0c88a 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -315,10 +315,7 @@ export const eventToCombination = (event: KeyboardEvent): HotkeyCombination => { } // event.codeからevent.key形式へと変換 // TODO: 主要なキーも使えるようにする - const eventKey = event.code - .replace(/Key|Digit|Numpad/, "") - .replace("Minus", "-") - .replace("Slash", "/"); + const eventKey = event.code.replace(/Key|Digit|Numpad/, ""); // 英字 数字 上下左右 Enter Space Backspace Delete Escape F1~ - /のみ認める if ( /^([A-Z]|\d|Arrow(Up|Down|Left|Right)|Enter|Space|Backspace|Delete|Escape|F\d+|-|\/)$/.test( From 4da51ea63eb39da2230fd226509e1199b5444903 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Mon, 20 May 2024 08:52:06 +0900 Subject: [PATCH 7/7] Apply suggestions from code review --- src/plugins/hotkeyPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index 816bb0c88a..1331354e6a 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -324,7 +324,7 @@ export const eventToCombination = (event: KeyboardEvent): HotkeyCombination => { ) { recordedCombination += eventKey; } - // 末尾がスペースならそれを削除 + // 修飾キーのみだった場合末尾がスペースになるので削除 recordedCombination = recordedCombination.replace(/\s$/, ""); return HotkeyCombination(recordedCombination); };