Skip to content

Commit

Permalink
refactor: Editor型を安全なものに
Browse files Browse the repository at this point in the history
  • Loading branch information
tsym77yoshi committed May 28, 2024
1 parent 9f62b17 commit c5c0e89
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/plugins/hotkeyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const useHotkeyManager = () => {
return { hotkeyManager, registerHotkeyWithCleanup };
};

// FIXME: EditorType型内の要素数が増えてきたら型定義をより一般な形に変更
type Editor = "talk" | "song" | "talk&song";

type BindingKey = string & { __brand: "BindingKey" }; // BindingKey専用のブランド型
Expand Down Expand Up @@ -257,10 +256,17 @@ export class HotkeyManager {
combinationToBindingKey(this.getSetting(item).combination) ==
combination,
)
.filter((item) =>
// エラー表記を回避するために三項演算子を利用
item.editor.split("&").includes(this.scope ? this.scope : ""),
);
.filter((item) => {
if (item.editor === "talk&song") {
return this.scope === "talk" || this.scope === "song";
} else if (item.editor === "talk") {
return this.scope === "talk";
} else if (item.editor === "song") {
return this.scope === "song";
} else {
console.error("scopeに対する処理が設定されていません");
}
});
if (actions.length == 0) {
return;
}
Expand Down

0 comments on commit c5c0e89

Please sign in to comment.