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
23 changes: 14 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がそうだった名残り
// NOTE: hotkeys-jsでは方向キーのarrowプレフィックスが不要
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,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からevent.key形式へと変換
// TODO: 主要なキーも使えるようにする
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(
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
eventKey,
)
) {
recordedCombination += eventKey;
}
// 修飾キーのみだった場合末尾がスペースになるので削除
recordedCombination = recordedCombination.replace(/\s$/, "");
return HotkeyCombination(recordedCombination);
};
Loading