feat: add keyboard shortcuts for zooming

This commit is contained in:
Johannes Millan 2019-02-12 23:40:11 +01:00
parent 53393309cd
commit ab32d465cb
5 changed files with 51 additions and 1 deletions

View file

@ -119,7 +119,29 @@ export class ShortcutService {
if (IS_ELECTRON) {
if (checkKeyCombo(ev, 'Ctrl+Shift+J')) {
window.ipcRenderer.send('TOGGLE_DEV_TOOLS');
} else if (checkKeyCombo(ev, keys.zoomIn)) {
this._zoom(0.05);
} else if (checkKeyCombo(ev, keys.zoomOut)) {
this._zoom(-0.05);
} else if (checkKeyCombo(ev, keys.zoomDefault)) {
this._zoom(0);
}
}
}
private _zoom(zoomDelta: number) {
const webFrame = this._electronService.webFrame;
let zoomFactor = webFrame.getZoomFactor();
zoomFactor += zoomDelta;
zoomFactor = Math.min(Math.max(zoomFactor, 0.1), 4);
if (zoomDelta === 0) {
webFrame.setZoomFactor(1);
} else {
webFrame.setZoomFactor(zoomFactor);
}
this._configService.updateSection('_uiHelper', {
_zoomFactor: zoomFactor
});
}
}

View file

@ -14,6 +14,9 @@ export type KeyboardConfig = Readonly<{
openProjectNotes: string,
toggleBookmarks: string;
openDistractionPanel: string,
zoomIn: string,
zoomOut: string,
zoomDefault: string,
focusLastActiveTask: string,
taskEditTitle: string,
taskToggleAdditionalInfoOpen: string,

View file

@ -43,6 +43,9 @@ export const DEFAULT_CFG: GlobalConfig = {
goToFocusMode: 'Shift+F',
goToSettings: '',
focusLastActiveTask: 'f',
zoomIn: 'Ctrl++',
zoomOut: 'Ctrl+-',
zoomDefault: 'Ctrl+0',
taskEditTitle: 'e',
taskToggleAdditionalInfoOpen: 'i',
taskOpenEstimationDialog: 't',

View file

@ -122,6 +122,27 @@ export const KEYBOARD_SETTINGS_FORM_CFG: ConfigFormSection = {
label: 'Focus last active task',
},
},
{
key: 'zoomIn',
type: 'keyboard',
templateOptions: {
label: 'Zoom in (Desktop only)',
},
},
{
key: 'zoomOut',
type: 'keyboard',
templateOptions: {
label: 'Zoom out (Desktop only)',
},
},
{
key: 'zoomDefault',
type: 'keyboard',
templateOptions: {
label: 'Zoom default (Desktop only)',
},
},
// TASKS
{
className: 'tpl',

View file

@ -4,6 +4,7 @@ const isSpecialKeyExactlyRight = (isKeyRequired: boolean, isKeyPressed: boolean)
export const checkKeyCombo = (ev: KeyboardEvent, comboToTest: string) => {
if (comboToTest) {
const isPlusKey = comboToTest.includes('++');
const comboKeys: string[] = comboToTest.split('+');
const standardKey: string = comboKeys[comboKeys.length - 1];
const sk = comboKeys.splice(0);
@ -13,7 +14,7 @@ export const checkKeyCombo = (ev: KeyboardEvent, comboToTest: string) => {
&& isSpecialKeyExactlyRight(sk.includes('Alt'), ev.altKey)
&& isSpecialKeyExactlyRight(sk.includes('Meta'), ev.metaKey)
&& (!(sk.includes('Shift')) || ev.shiftKey === true)
&& ev.key === standardKey;
&& (ev.key === standardKey || isPlusKey && ev.key === '+');
} else {
return null;
}