Skip to content

Commit

Permalink
Keyboard Shortcut Fixes (#40)
Browse files Browse the repository at this point in the history
* Initializing Keyboard_Shortcut_Fixes for empty Pull Request

* Add `command` modifiers to hotkeys where it makes sense

* Remove weird misplaced text

* Format hotkey help text to show the appropriate hints
  • Loading branch information
V13Axel authored Nov 17, 2023
1 parent 3a9c49b commit 60531fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ onMounted(async () => {
);
hotkeys.register(
"ctrl+shift+\\",
"ctrl+shift+\\, command+shift+\\",
"Toggles light/dark theme",
() => {
toggleTheme();
Expand Down
16 changes: 13 additions & 3 deletions src/components/KeyboardModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ import { onBeforeMount } from "vue";
const modals = useModals();
const hotkeys = useHotkeys();
const mac = navigator.platform.startsWith('Mac');
// If the hotkey is "ctrl+/, command+/", then we want to only display "⌘+/" on Mac
// and "Ctrl+/" everywhere else. If the hotkey has no ctrl or command modifiers,
// such as "esc", then we want to display just "Esc" everywhere.
function formatHotkey(hotkey) {
return (hotkey.includes("ctrl") && hotkey.includes("command"))
? hotkey.split(", ")[mac ? 1 : 0].replace("command", "").replace("ctrl", "Ctrl")
: hotkey.slice(0, 1).toUpperCase() + hotkey.slice(1);
}
onBeforeMount(() => {
hotkeys.register(
"ctrl+/",
"ctrl+/, command+/",
"Displays this help window",
() => {
modals.toggle("keyboard");
Expand All @@ -27,12 +37,12 @@ onBeforeMount(() => {
<div
class="my-2 max-h-96 overflow-y-auto overflow-x-hidden text-gray-700 dark:text-gray-300"
>
<div class="grid grid-cols-2 gap-x-4 gap-y-2">
<div class="grid grid-cols-2 gap-x-8 gap-y-3">
<div v-for="hotkey in hotkeys.help" :key="hotkey.shortcut">
<div class="flex justify-between">
<kbd
class="inline-flex items-center border border-gray-200 dark:border-gray-600 rounded px-2 text-sm font-sans font-medium text-gray-400"
v-text="hotkey.shortcut"
v-text="formatHotkey(hotkey.shortcut)"
></kbd>
<div v-text="hotkey.description"></div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/MonsterTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const pagination = computed(() => {
onBeforeMount(() => {
hotkeys.register(
"ctrl+[",
"ctrl+[, command+[",
"Previous monsters search page",
() => {
currentPage.value--;
Expand All @@ -111,7 +111,7 @@ onBeforeMount(() => {
);
hotkeys.register(
"ctrl+]",
"ctrl+], command+]",
"Next monsters search page",
() => {
currentPage.value++;
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const searchBox = ref(null);
onMounted(() => {
hotkeys.register(
"ctrl+k",
"ctrl+k, command+k",
"Focus the search box",
() => {
searchBox.value.focus();
Expand Down
13 changes: 7 additions & 6 deletions src/views/GeneratorView.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
show
<script setup></script>

<script>
Expand Down Expand Up @@ -36,7 +35,7 @@ export default {
data() {
return {
userWantsFilters: this.filtersTest(),
alwaysShowFilters: false,
alwaysShowFilters: this.filtersTest(),
mobileEncounterTab: false,
};
},
Expand Down Expand Up @@ -69,18 +68,20 @@ export default {
setupHotkeys() {
this.hotkeys.register(
"ctrl+f",
"ctrl+f, command+f",
"Toggle the filters sidebar",
() => {
this.userWantsFilters = this.filtersTest() ? true : !this.userWantsFilters;
this.userWantsFilters = this.filtersTest()
? true
: !this.userWantsFilters;
return false;
},
0
);
this.hotkeys.register(
"ctrl+s",
"ctrl+s, command+s",
"Save the current encounter",
() => {
this.encounter.save();
Expand All @@ -90,7 +91,7 @@ export default {
);
this.hotkeys.register(
"ctrl+g",
"ctrl+g, command+g",
"Generate an encounter",
() => {
this.encounter.generateRandom();
Expand Down

0 comments on commit 60531fa

Please sign in to comment.