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

ショートカットキーとしてCommandキーを使えるようにする #1865

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/plugins/hotkeyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const useHotkeyManager = () => {

type Editor = "talk" | "song";

type BindingKey = string & { __brand: "BindingKey" }; // BindingKey専用のブランド型

/**
* ショートカットキーの処理を登録するための型。
*/
Expand All @@ -50,16 +52,17 @@ export type HotkeyAction = {

export type HotkeysJs = {
(
key: string,
key: BindingKey,
options: {
scope: string;
},
callback: (e: KeyboardEvent) => void
): void;
unbind: (key: string, scope: string) => void;
unbind: (key: BindingKey, scope: string) => void;
setScope: (scope: string) => void;
};

// デフォルトはテキストボックス内でショートカットキー無効なので有効にする
hotkeys.filter = () => {
return true;
};
Expand Down Expand Up @@ -269,8 +272,19 @@ export class HotkeyManager {
}
}

const combinationToBindingKey = (combination: HotkeyCombination) => {
return combination.toLowerCase().replaceAll(" ", "+");
/** hotkeys-js用のキーに変換する */
const combinationToBindingKey = (
combination: HotkeyCombination
): BindingKey => {
// MetaキーはCommandキーとして扱う
// NOTE: hotkeys-jsにはWinキーが無く、Commandキーとして扱われている
// NOTE: Metaキーは以前採用していたmousetrapがそうだった名残り
const bindingKey = combination
.toLowerCase()
.split(" ")
.map((key) => (key === "meta" ? "command" : key))
.join("+");
return bindingKey as BindingKey;
};

export const hotkeyPlugin: Plugin = {
Expand Down
Loading