Работа над хоткеями

This commit is contained in:
Book Pauk
2020-03-15 21:29:58 +07:00
parent 2db8876c66
commit dc3f682d2d
3 changed files with 39 additions and 7 deletions

View File

@@ -339,6 +339,11 @@ class Reader extends Vue {
this.showToolButton = settings.showToolButton;
this.enableSitesFilter = settings.enableSitesFilter;
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
this.$root.readerActionByKeyEvent = (event) => {
return this.readerActionByKeyCode[utils.keyEventToCode(event)];
}
this.updateHeaderMinWidth();
}
@@ -1090,9 +1095,10 @@ class Reader extends Vue {
}
keyHook(event) {
let result = false;
if (this.$root.rootRoute() == '/reader') {
if (this.$root.stdDialog.active || this.$refs.dialog1.active || this.$refs.dialog2.active)
return;
return result;
let handled = false;
if (!handled && this.helpActive)
@@ -1117,17 +1123,26 @@ class Reader extends Vue {
handled = this.$refs.page.keyHook(event);
if (!handled && event.type == 'keydown') {
if (event.code == 'Escape')
const action = this.$root.readerActionByKeyEvent(event);
if (action == 'loader') {
this.loaderToggle();
result = true;
}
if (this.activePage == 'TextPage') {
switch (event.code) {
case 'KeyH':
case 'F1':
result = true;
switch (action) {
case 'help':
this.helpToggle();
event.preventDefault();
event.stopPropagation();
break;
default:
result = false;
break;
}
switch (event.code) {
case 'KeyZ':
this.scrollingToggle();
break;
@@ -1166,6 +1181,7 @@ class Reader extends Vue {
}
}
}
return result;
}
}
//-----------------------------------------------------------------------------

View File

@@ -218,4 +218,14 @@ export function keyEventToCode(event) {
result.push(event.code);
return result.join('+');
}
}
export function userHotKeysObjectSwap(userHotKeys) {
let result = {};
for (const [name, codes] of Object.entries(userHotKeys)) {
for (const code of codes) {
result[code] = name;
}
}
return result;
}

View File

@@ -14,6 +14,7 @@ const readerActions = {
'recentBooks': 'Открыть недавние',
};
//readerActions[name]
const toolButtons = [
{name: 'undoAction', show: true},
{name: 'redoAction', show: true},
@@ -27,8 +28,10 @@ const toolButtons = [
{name: 'recentBooks', show: true},
];
//readerActions[name]
const hotKeys = [
{name: 'help', text: readerActions['help'], code: ['F1', 'KeyH']},
{name: 'help', codes: ['F1', 'KeyH']},
{name: 'loader', codes: ['Escape']},
];
const fonts = [
@@ -208,6 +211,7 @@ const settingDefaults = {
fontShifts: {},
showToolButton: {},
userHotKeys: {},
};
for (const font of fonts)
@@ -216,6 +220,8 @@ for (const font of webFonts)
settingDefaults.fontShifts[font.name] = font.fontVertShift;
for (const button of toolButtons)
settingDefaults.showToolButton[button.name] = button.show;
for (const hotKey of hotKeys)
settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
// initial state
const state = {