2
0
mirror of https://github.com/frappe/books.git synced 2025-02-13 17:39:09 +00:00

incr: mods not added to pressed

This commit is contained in:
18alantom 2023-01-30 12:27:21 +05:30
parent 67f8879551
commit e4fbecc914
2 changed files with 32 additions and 13 deletions

View File

@ -237,15 +237,14 @@ export default {
const shortcuts = [
{
shortcut: ['KeyK', this.modKey],
shortcut: 'KeyK',
callback: ifClose(() => this.open()),
},
{ shortcut: ['Escape'], callback: ifOpen(() => this.close()) },
];
for (const i in searchGroups) {
shortcuts.push({
shortcut: [this.modKey, `Digit${Number(i) + 1}`],
shortcut: `Digit${Number(i) + 1}`,
callback: ifOpen(() => {
const group = searchGroups[i];
const value = this.searcher.filters.groupFilters[group];
@ -262,12 +261,20 @@ export default {
},
setShortcuts() {
for (const { shortcut, callback } of this.getShortcuts()) {
this.shortcuts.meta.set(shortcut, callback);
if (this.platform === 'Mac') {
this.shortcuts.meta.set([shortcut], callback);
} else {
this.shortcuts.ctrl.set([shortcut], callback);
}
}
},
deleteShortcuts() {
for (const { shortcut } of this.getShortcuts()) {
this.shortcuts.meta.delete(shortcut);
if (this.platform === 'Mac') {
this.shortcuts.meta.delete([shortcut]);
} else {
this.shortcuts.ctrl.delete([shortcut]);
}
}
},
modKeyText(key) {
@ -305,7 +312,7 @@ export default {
},
select(idx) {
this.idx = idx ?? this.idx;
this.suggestions[this.idx]?.action();
this.suggestionsthis.idx?.action();
this.close();
},
scrollToHighlighted() {

View File

@ -1,4 +1,4 @@
import { onMounted, onUnmounted, reactive, ref, unref, watch } from 'vue';
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
interface ModMap {
alt: boolean;
@ -114,6 +114,7 @@ export class Shortcuts {
}
export function useKeys() {
const isMac = navigator.userAgent.indexOf('Mac') !== -1;
const keys: Keys = reactive({
pressed: new Set<string>(),
alt: false,
@ -124,21 +125,32 @@ export function useKeys() {
});
const keydownListener = (e: KeyboardEvent) => {
keys.pressed.add(e.code);
keys.alt = e.altKey;
keys.ctrl = e.ctrlKey;
keys.meta = e.metaKey;
keys.shift = e.shiftKey;
keys.repeat = e.repeat;
const { code } = e;
if (
code.startsWith('Alt') ||
code.startsWith('Ctrl') ||
code.startsWith('Meta') ||
code.startsWith('Shift')
) {
return;
}
keys.pressed.add(code);
};
const keyupListener = (e: KeyboardEvent) => {
keys.pressed.delete(e.code);
// Key up won't trigger on macOS for other keys.
if (e.code === 'MetaLeft') {
keys.pressed.clear();
const { code } = e;
if (code.startsWith('Meta') && isMac) {
return keys.pressed.clear();
}
keys.pressed.delete(code);
};
onMounted(() => {