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: ショートカットキー周りをHotkeyManagerにまとめる #1822

Merged
merged 52 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9d55fb9
Add: HotkeyManagerを追加
sevenc-nanashi Feb 3, 2024
421903b
Add: とりあえずUndo/Redoは動いた
sevenc-nanashi Feb 3, 2024
22c572c
Change: Pluginに
sevenc-nanashi Feb 3, 2024
a83f4a3
Change: hotkey-jsに
sevenc-nanashi Feb 3, 2024
cd5469c
Change: hotkeyManagerに置き換え
sevenc-nanashi Feb 3, 2024
f5fe090
Change: デフォルトパラメータに
sevenc-nanashi Feb 3, 2024
b93a07c
Code: ドキュメントを追加
sevenc-nanashi Feb 3, 2024
60c7336
Add: sing側に同じ名前でショートカットを登録できるように
sevenc-nanashi Feb 4, 2024
35dce47
Revert: Spaceキー再生のコードを削除
sevenc-nanashi Feb 4, 2024
5e9d70e
Improve: 可読性を改善
sevenc-nanashi Feb 6, 2024
171d8d2
Delete: keepDefaultBehaviorを削除
sevenc-nanashi Feb 6, 2024
cf5c441
Change: scopeを使うように
sevenc-nanashi Feb 6, 2024
ccc6b62
Code: 「ショートカットキーの処理」を使うように
sevenc-nanashi Feb 6, 2024
933cc43
Merge: main -> refactor/hotkey
sevenc-nanashi Feb 6, 2024
e18c353
Fix: 同じキーバインドが登録されてると片方が動かなくなるのを修正
sevenc-nanashi Feb 8, 2024
693f738
Code: 可読性を向上
sevenc-nanashi Feb 10, 2024
735a6c7
Merge: main -> refactor/hotkey
sevenc-nanashi Feb 10, 2024
a226127
Code: 変数名周りを改修
sevenc-nanashi Feb 10, 2024
14c62cf
Change: HotkeyAction -> HotkeyActionName
sevenc-nanashi Feb 10, 2024
796405a
Change: ActionKey -> ActionId
sevenc-nanashi Feb 10, 2024
bd74cfc
Change: action ->name
sevenc-nanashi Feb 10, 2024
473a780
Change: window.electron.logInfoをを使うようにする
sevenc-nanashi Feb 10, 2024
84729c8
Code: 変数名を変更
sevenc-nanashi Feb 10, 2024
3881365
Change: undefined | HotkeySetting[]にする
sevenc-nanashi Feb 10, 2024
2a0b170
Add: テストを追加
sevenc-nanashi Feb 10, 2024
c3fac82
Refactor: refreshBindingsを分解
sevenc-nanashi Feb 10, 2024
299dc1c
Change: hotkeys.filterを一番上に持ってくる
sevenc-nanashi Feb 11, 2024
45d1992
Change: getSettingでthrowするようにする
sevenc-nanashi Feb 11, 2024
44f2bb7
Delete: eslintのignoreを使わないコードにする
sevenc-nanashi Feb 11, 2024
10f474f
Code: コメントを追加
sevenc-nanashi Feb 11, 2024
1571003
Change: as unknown asをなくす
sevenc-nanashi Feb 11, 2024
5e3c03f
Fix: 割り当て -> 未割り当て -> 割り当ての挙動を修正
sevenc-nanashi Feb 11, 2024
035eb23
Change: logをDIする
sevenc-nanashi Feb 11, 2024
c68fc07
Merge: main -> refactor/hotkey
sevenc-nanashi Feb 11, 2024
1ae9b38
Code: コメントを追加
sevenc-nanashi Feb 11, 2024
1452b82
Change: 条件を変更
sevenc-nanashi Feb 14, 2024
5c63293
下に移動
Hiroshiba Feb 14, 2024
7a5e6f8
Merge remote-tracking branch 'upstream/main' into pr/sevenc-nanashi/1…
Hiroshiba Feb 14, 2024
96ed5d7
to combination
Hiroshiba Feb 14, 2024
ed32545
Fix: 良い感じにクリーンアップするように
sevenc-nanashi Feb 15, 2024
5475247
Fix: テストを修正
sevenc-nanashi Feb 15, 2024
925fd13
Improve: 良い感じに
sevenc-nanashi Feb 16, 2024
017d69e
Improve: エラーメッセージを改善
sevenc-nanashi Feb 16, 2024
c90ae78
Change: IDを使わないように
sevenc-nanashi Feb 18, 2024
e81b28a
Refactor: isSameHotkeyTarget/isNotSameHotkeyTargetを追加
sevenc-nanashi Feb 18, 2024
81afdfc
Delete: unbindUnregisteredCombinationsを削除
sevenc-nanashi Feb 18, 2024
22e0236
Merge: main -> refactor/hotkey
sevenc-nanashi Feb 19, 2024
02ebfdd
unbindedCombinationsを下に
Hiroshiba Feb 20, 2024
7fefe74
doc集約
Hiroshiba Feb 20, 2024
92551fe
プライベート変数の説明追加
Hiroshiba Feb 20, 2024
116a796
Code: コメントをdoc commentに
sevenc-nanashi Feb 20, 2024
ea7a853
Change: beforeEachで登録するのをやめる
sevenc-nanashi Feb 20, 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
40 changes: 14 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"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",
Expand Down Expand Up @@ -80,7 +81,6 @@
"@types/encoding-japanese": "1.0.18",
"@types/glob": "8.0.0",
"@types/markdown-it": "12.2.0",
"@types/mousetrap": "1.6.8",
"@types/multistream": "4.1.0",
"@types/semver": "7.3.9",
"@types/unzipper": "0.10.5",
Expand Down Expand Up @@ -110,7 +110,6 @@
"license-checker": "25.0.1",
"markdownlint": "0.31.1",
"markdownlint-cli": "0.37.0",
"mousetrap": "1.6.5",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mousetrap、

  • 4年以上コミットがない
  • テキスト欄で効くように出来ない(stopCallback試したけどダメだった)

ので、代替に挙げられているhotkey-jsを使う用にしました。

"node-fetch": "3.3.1",
"optionator": "0.9.1",
"prettier": "2.3.0",
Expand Down
38 changes: 6 additions & 32 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
</template>

<script setup lang="ts">
import { watch, onMounted, ref, computed } from "vue";
import { watch, onMounted, ref, computed, toRaw } from "vue";
import { useGtm } from "@gtm-support/vue-gtm";
import { useRoute } from "vue-router";
import Mousetrap from "mousetrap";
import { EngineId } from "./type/preload";
import ErrorBoundary from "@/components/ErrorBoundary.vue";
import { useStore } from "@/store";
import { isOnCommandOrCtrlKeyDown } from "@/store/utility";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";

const store = useStore();
const route = useRoute();
Expand Down Expand Up @@ -49,39 +48,14 @@ watch(
);

// ソフトウェアを初期化
const hotkeyManager = useHotkeyManager();
const isEnginesReady = ref(false);
onMounted(async () => {
await store.dispatch("INIT_VUEX");

// Electronのデフォルトのundo/redoを無効化
const disableDefaultUndoRedo = (event: KeyboardEvent) => {
// ctrl+z, ctrl+shift+z, ctrl+y
if (
isOnCommandOrCtrlKeyDown(event) &&
(event.key == "z" || (!event.shiftKey && event.key == "y"))
) {
event.preventDefault();
}
};
document.addEventListener("keydown", disableDefaultUndoRedo);

// ショートカットキー操作を止める条件の設定
// 止めるなら`true`を返す
Mousetrap.prototype.stopCallback = (
e: Mousetrap.ExtendedKeyboardEvent, // 未使用
element: Element,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
combo: string // 未使用
) => {
return (
element.tagName === "INPUT" ||
element.tagName === "SELECT" ||
element.tagName === "TEXTAREA" ||
(element instanceof HTMLElement && element.contentEditable === "true") ||
// メニュー項目ではショートカットキーを無効化
element.classList.contains("q-item")
);
};
const hotkeySettings = store.state.hotkeySettings;

hotkeyManager.load(structuredClone(toRaw(hotkeySettings)));

// エンジンの初期化開始

Expand Down
7 changes: 6 additions & 1 deletion src/components/Dialog/HotkeySettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import { useStore } from "@/store";
import { parseCombo } from "@/store/setting";
import { HotkeyActionType, HotkeySettingType } from "@/type/preload";
import { useHotkeyManager, parseCombo } from "@/plugins/hotkeyPlugin";

const props =
defineProps<{
Expand Down Expand Up @@ -277,7 +277,12 @@ const recordCombination = (event: KeyboardEvent) => {
}
};

const hotkeyManager = useHotkeyManager();
const changeHotkeySettings = (action: string, combo: string) => {
hotkeyManager.replace({
action: action as HotkeyActionType,
combination: combo,
});
return store.dispatch("SET_HOTKEY_SETTINGS", {
data: {
action: action as HotkeyActionType,
Expand Down
78 changes: 33 additions & 45 deletions src/components/HeaderBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ import {
generateAndSaveOneAudioWithDialog,
} from "@/components/Dialog/Dialog";
import { useStore } from "@/store";
import { setHotkeyFunctions } from "@/store/setting";
import {
HotkeyActionType,
HotkeyReturnType,
ToolbarButtonTagType,
} from "@/type/preload";
import { ToolbarButtonTagType } from "@/type/preload";
import { getToolbarButtonName } from "@/store/utility";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";

type ButtonContent = {
text: string;
Expand All @@ -54,47 +50,39 @@ const nowPlayingContinuously = computed(
() => store.state.nowPlayingContinuously
);

const undoRedoHotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
// undo
[
"元に戻す",
() => {
if (!uiLocked.value && canUndo.value) {
undo();
}
return false;
},
],
// redo
[
"やり直す",
() => {
if (!uiLocked.value && canRedo.value) {
redo();
}
return false;
},
],
]);
setHotkeyFunctions(undoRedoHotkeyMap);
const hotkeyManager = useHotkeyManager();
hotkeyManager.register({
editor: "talk",
action: "元に戻す",
callback: () => {
if (!uiLocked.value && canUndo.value) {
undo();
}
},
});
hotkeyManager.register({
editor: "talk",
action: "やり直す",
callback: () => {
if (!uiLocked.value && canRedo.value) {
redo();
}
},
});

const hotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
// play/stop continuously
[
"連続再生/停止",
() => {
if (!uiLocked.value) {
if (nowPlayingContinuously.value) {
stop();
} else {
playContinuously();
}
hotkeyManager.register({
editor: "talk",
action: "連続再生/停止",
callback: () => {
if (!uiLocked.value) {
if (nowPlayingContinuously.value) {
stop();
} else {
playContinuously();
}
},
],
]);

setHotkeyFunctions(hotkeyMap);
}
},
});

const undo = () => {
store.dispatch("UNDO");
Expand Down
9 changes: 0 additions & 9 deletions src/components/Sing/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<script setup lang="ts">
import { computed } from "vue";
import { useStore } from "@/store";
import { HotkeyActionType, HotkeyReturnType } from "@/type/preload";
import { setHotkeyFunctions } from "@/store/setting";
import BaseMenuBar, { MenuItemData } from "@/components/BaseMenuBar.vue";

const store = useStore();
Expand Down Expand Up @@ -54,11 +52,4 @@ const fileSubMenuData: MenuItemData[] = [
disableWhenUiLocked: true,
},
];

const hotkeyMap = new Map<HotkeyActionType, () => HotkeyReturnType>([
// NOTE: 初期設定なし
// ["新規", createNewSingProject],
]);

setHotkeyFunctions(hotkeyMap);
</script>
14 changes: 14 additions & 0 deletions src/components/Sing/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,22 @@ import {
} from "@/sing/domain";
import CharacterMenuButton from "@/components/Sing/CharacterMenuButton.vue";
import { getStyleDescription } from "@/sing/viewHelper";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";

const store = useStore();
const hotkeyManager = useHotkeyManager();

hotkeyManager.register({
action: "再生/停止",
editor: "song",
callback: () => {
if (nowPlaying.value) {
stop();
} else {
play();
}
},
});
sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved

const userOrderedCharacterInfos = computed(() =>
store.getters.USER_ORDERED_CHARACTER_INFOS("singerLike")
Expand Down
Loading
Loading