Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: ホットキーでshift+数字を登録時のエラーをなくす #1964

Merged
merged 7 commits into from
May 20, 2024
26 changes: 17 additions & 9 deletions src/plugins/hotkeyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,12 @@ const combinationToBindingKey = (
// MetaキーはCommandキーとして扱う
// NOTE: hotkeys-jsにはWinキーが無く、Commandキーとして扱われている
// NOTE: Metaキーは以前採用していたmousetrapがそうだった名残り
// hotkeys-jsでは方向キーをup, down, left, rightで表す
tsym77yoshi marked this conversation as resolved.
Show resolved Hide resolved
const bindingKey = combination
.toLowerCase()
.split(" ")
.map((key) => (key === "meta" ? "command" : key))
.map((key) => key.replace("arrow", ""))
.join("+");
return bindingKey as BindingKey;
};
Expand Down Expand Up @@ -311,15 +313,21 @@ 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から以前のevent.key形式へと変換
// 列挙するのは将来的に変更する
tsym77yoshi marked this conversation as resolved.
Show resolved Hide resolved
const eventKey = event.code
.replace(/Key|Digit|Numpad/, "")
.replace("Minus", "-")
.replace("Slash", "/");
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
// 英字 数字 上下左右 Enter Space Backspace Delete Escape F1~ - /のみ認める
if (
/^([A-Z]|\d|Arrow(Up|Down|Left|Right)|Enter|Space|Backspace|Delete|Escape|F\d+|-|\/)$/.test(
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
eventKey,
)
) {
recordedCombination += eventKey;
}
// 末尾がスペースならそれを削除
recordedCombination = recordedCombination.replace(/\s$/, "");
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
return HotkeyCombination(recordedCombination);
};
Loading