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

change: HotkeysJSを代替 #1984

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5171fa3
change: HotkeysJSを代替
tsym77yoshi Apr 7, 2024
0cb1bc8
fix:console.log削除
tsym77yoshi Apr 7, 2024
9915d02
change: HotkeysJSを代替
tsym77yoshi Apr 7, 2024
53b5fc8
fix: 基本部分の修正
tsym77yoshi Apr 30, 2024
0b064f2
Merge branch 'change-hotkey' of https://github.com/tsym77yoshi/voicev…
tsym77yoshi Apr 30, 2024
d5e022f
remove: test以外の部分のhotkeys-js関連を削除
tsym77yoshi May 6, 2024
2cf7f28
change: キー入力のテストの変更
tsym77yoshi May 6, 2024
275ca8a
remove: 以前のコメントを削除
tsym77yoshi May 6, 2024
3543da0
Merge branch 'main' into change-hotkey
tsym77yoshi May 6, 2024
9ecd6cf
fix: lintエラー修正
tsym77yoshi May 6, 2024
e9a14fb
fix: lintエラー再修正
tsym77yoshi May 6, 2024
ddcb089
FIX: 順番が違う際に動作しない問題を修正
tsym77yoshi May 14, 2024
3b0ed98
refactor: どのエディターでも実行されるショートカットアクションを登録できる関数を作る
tsym77yoshi May 14, 2024
ccda7f6
FIX: 同じショートカットキーに2つ以上の操作を割り当てられるように
tsym77yoshi May 14, 2024
f9fc14c
Update ダイアログ内でホットキーが効かないように修正
tsym77yoshi May 16, 2024
9f431ef
Merge branch 'main' into change-hotkey
tsym77yoshi May 26, 2024
78734f1
addとremoveを対に
tsym77yoshi May 27, 2024
7bd034a
hotkeyPlugin内で初期設定を消す
tsym77yoshi May 27, 2024
9f62b17
消し忘れを削除
tsym77yoshi May 27, 2024
c5c0e89
refactor: Editor型を安全なものに
tsym77yoshi May 28, 2024
0a82b96
テストをvi.fn()に
tsym77yoshi May 28, 2024
cfc1433
不要なコメントの削除
tsym77yoshi May 28, 2024
008cd8a
fix: unregisterのtestを正しい意図通りに
tsym77yoshi May 28, 2024
317c672
add: testの意図をコメントに
tsym77yoshi May 29, 2024
7ef2b95
Merge branch 'main' into change-hotkey
tsym77yoshi May 29, 2024
8df31c6
fix: lint修正
tsym77yoshi May 29, 2024
7a804fa
Merge branch 'change-hotkey' of https://github.com/tsym77yoshi/voicev…
tsym77yoshi May 29, 2024
ac02817
Merge branch 'change-hotkey' of https://github.com/tsym77yoshi/voicev…
tsym77yoshi May 29, 2024
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
Prev Previous commit
Next Next commit
remove: test以外の部分のhotkeys-js関連を削除
tsym77yoshi committed May 6, 2024
commit d5e022fb3339173c79fc0db5639599fd48e9dff2
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@
"electron-window-state": "5.0.3",
"encoding-japanese": "1.0.30",
"glob": "8.0.3",
"hotkeys-js": "3.13.6",
"immer": "9.0.21",
"markdown-it": "13.0.2",
"move-file": "3.0.0",
47 changes: 13 additions & 34 deletions src/plugins/hotkeyPlugin.ts
Original file line number Diff line number Diff line change
@@ -4,11 +4,10 @@
* HotkeyAction: 実行する処理の名前とコールバックのペア
* HotkeySetting: ユーザーが設定できるもの。ActionとCobinationのペア
* Combination: ショートカットキーを文字列で表したもの
* binding: hotkeys-js に登録したコールバック
* bindingKey: hotkeys-js で使う、キーの文字列表記
* binding: 登録したコールバック
* bindingKey: キーの文字列表記
*/
import { Plugin, inject, onMounted, onUnmounted } from "vue";
import hotkeys from "hotkeys-js";
import {
HotkeyActionNameType,
HotkeyCombination,
@@ -50,22 +49,6 @@ export type HotkeyAction = {
callback: (e: KeyboardEvent) => void;
};

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

// デフォルトはテキストボックス内でショートカットキー無効なので有効にする
hotkeys.filter = () => {
return true;
};
type Log = (message: string, ...args: unknown[]) => void;

type RegisteredCombination = {
@@ -95,20 +78,17 @@ export class HotkeyManager {
private scope: Editor = "talk";
/** ユーザーのショートカットキー設定 */
private settings: HotkeySettingType[] | undefined; // ユーザーのショートカットキー設定
/** hotkeys-jsに登録されたショートカットキーの組み合わせ */
/** 登録されたショートカットキーの組み合わせ */
private registeredCombinations: RegisteredCombination[] = [];

private hotkeys: HotkeysJs;
private log: Log;

constructor(
hotkeys_: HotkeysJs = hotkeys,
log: Log = (message: string, ...args: unknown[]) => {
window.backend.logInfo(`[HotkeyManager] ${message}`, ...args);
}
) {
this.log = log;
this.hotkeys = hotkeys_;
}

/**
@@ -263,11 +243,15 @@ export class HotkeyManager {
element.tagName === "TEXTAREA" ||
element.contentEditable === "true");

const combination = eventToCombination(e);
const combination = combinationToBindingKey(eventToCombination(e));

const action = this.actions
const action = this.actions
.filter((item) => !isInTextbox || item.enableInTextbox)
.filter((item) => this.getSetting(item).combination == combination)
.filter(
(item) =>
combinationToBindingKey(this.getSetting(item).combination) ==
combination,
)
.find((item) => item.editor == this.scope);
if (action == null) {
return;
@@ -277,19 +261,14 @@ export class HotkeyManager {
}
}

/** 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;
return combination as unknown as BindingKey;
};

export const hotkeyPlugin: Plugin = {