Работа над хоткеями
This commit is contained in:
@@ -339,6 +339,11 @@ class Reader extends Vue {
|
|||||||
this.showToolButton = settings.showToolButton;
|
this.showToolButton = settings.showToolButton;
|
||||||
this.enableSitesFilter = settings.enableSitesFilter;
|
this.enableSitesFilter = settings.enableSitesFilter;
|
||||||
|
|
||||||
|
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
|
||||||
|
this.$root.readerActionByKeyEvent = (event) => {
|
||||||
|
return this.readerActionByKeyCode[utils.keyEventToCode(event)];
|
||||||
|
}
|
||||||
|
|
||||||
this.updateHeaderMinWidth();
|
this.updateHeaderMinWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1090,9 +1095,10 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keyHook(event) {
|
keyHook(event) {
|
||||||
|
let result = false;
|
||||||
if (this.$root.rootRoute() == '/reader') {
|
if (this.$root.rootRoute() == '/reader') {
|
||||||
if (this.$root.stdDialog.active || this.$refs.dialog1.active || this.$refs.dialog2.active)
|
if (this.$root.stdDialog.active || this.$refs.dialog1.active || this.$refs.dialog2.active)
|
||||||
return;
|
return result;
|
||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
if (!handled && this.helpActive)
|
if (!handled && this.helpActive)
|
||||||
@@ -1117,17 +1123,26 @@ class Reader extends Vue {
|
|||||||
handled = this.$refs.page.keyHook(event);
|
handled = this.$refs.page.keyHook(event);
|
||||||
|
|
||||||
if (!handled && event.type == 'keydown') {
|
if (!handled && event.type == 'keydown') {
|
||||||
if (event.code == 'Escape')
|
const action = this.$root.readerActionByKeyEvent(event);
|
||||||
|
if (action == 'loader') {
|
||||||
this.loaderToggle();
|
this.loaderToggle();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.activePage == 'TextPage') {
|
if (this.activePage == 'TextPage') {
|
||||||
switch (event.code) {
|
result = true;
|
||||||
case 'KeyH':
|
switch (action) {
|
||||||
case 'F1':
|
case 'help':
|
||||||
this.helpToggle();
|
this.helpToggle();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.code) {
|
||||||
case 'KeyZ':
|
case 'KeyZ':
|
||||||
this.scrollingToggle();
|
this.scrollingToggle();
|
||||||
break;
|
break;
|
||||||
@@ -1166,6 +1181,7 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -219,3 +219,13 @@ export function keyEventToCode(event) {
|
|||||||
|
|
||||||
return result.join('+');
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const readerActions = {
|
|||||||
'recentBooks': 'Открыть недавние',
|
'recentBooks': 'Открыть недавние',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//readerActions[name]
|
||||||
const toolButtons = [
|
const toolButtons = [
|
||||||
{name: 'undoAction', show: true},
|
{name: 'undoAction', show: true},
|
||||||
{name: 'redoAction', show: true},
|
{name: 'redoAction', show: true},
|
||||||
@@ -27,8 +28,10 @@ const toolButtons = [
|
|||||||
{name: 'recentBooks', show: true},
|
{name: 'recentBooks', show: true},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//readerActions[name]
|
||||||
const hotKeys = [
|
const hotKeys = [
|
||||||
{name: 'help', text: readerActions['help'], code: ['F1', 'KeyH']},
|
{name: 'help', codes: ['F1', 'KeyH']},
|
||||||
|
{name: 'loader', codes: ['Escape']},
|
||||||
];
|
];
|
||||||
|
|
||||||
const fonts = [
|
const fonts = [
|
||||||
@@ -208,6 +211,7 @@ const settingDefaults = {
|
|||||||
|
|
||||||
fontShifts: {},
|
fontShifts: {},
|
||||||
showToolButton: {},
|
showToolButton: {},
|
||||||
|
userHotKeys: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const font of fonts)
|
for (const font of fonts)
|
||||||
@@ -216,6 +220,8 @@ for (const font of webFonts)
|
|||||||
settingDefaults.fontShifts[font.name] = font.fontVertShift;
|
settingDefaults.fontShifts[font.name] = font.fontVertShift;
|
||||||
for (const button of toolButtons)
|
for (const button of toolButtons)
|
||||||
settingDefaults.showToolButton[button.name] = button.show;
|
settingDefaults.showToolButton[button.name] = button.show;
|
||||||
|
for (const hotKey of hotKeys)
|
||||||
|
settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
|
||||||
|
|
||||||
// initial state
|
// initial state
|
||||||
const state = {
|
const state = {
|
||||||
|
|||||||
Reference in New Issue
Block a user