notify keypress changes
add num keyboard shortcuts
This commit is contained in:
parent
259c4b3e3c
commit
fbbd002949
|
@ -12,6 +12,7 @@ import {
|
||||||
togglePixelNotify,
|
togglePixelNotify,
|
||||||
toggleMute,
|
toggleMute,
|
||||||
notify,
|
notify,
|
||||||
|
selectCanvas,
|
||||||
} from '../actions';
|
} from '../actions';
|
||||||
|
|
||||||
const usedKeys = ['g', 'h', 'x', 'm', 'r', 'p'];
|
const usedKeys = ['g', 'h', 'x', 'm', 'r', 'p'];
|
||||||
|
@ -24,12 +25,27 @@ function onKeyPress(event: KeyboardEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let { key } = event;
|
||||||
|
|
||||||
|
const num = Number(key);
|
||||||
|
if (!Number.isNaN(num) && num > 0) {
|
||||||
|
// switch to canvas on num keys
|
||||||
|
const { canvases } = store.getState().canvas;
|
||||||
|
const canvasIds = Object.keys(canvases).filter((id) => !canvases[id].hid);
|
||||||
|
if (num <= canvasIds.length) {
|
||||||
|
const canvasId = canvasIds[num - 1];
|
||||||
|
store.dispatch(selectCanvas(canvasId));
|
||||||
|
const canvasName = canvases[canvasId].title;
|
||||||
|
store.dispatch(notify(t`Switched to ${canvasName}`));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if char of key isn't used by a keybind,
|
* if char of key isn't used by a keybind,
|
||||||
* we check if the key location is where a
|
* we check if the key location is where a
|
||||||
* key that is used would be on QWERTY
|
* key that is used would be on QWERTY
|
||||||
*/
|
*/
|
||||||
let { key } = event;
|
|
||||||
if (!usedKeys.includes(key)) {
|
if (!usedKeys.includes(key)) {
|
||||||
key = event.code;
|
key = event.code;
|
||||||
if (!key.startsWith('Key')) {
|
if (!key.startsWith('Key')) {
|
||||||
|
@ -41,19 +57,27 @@ function onKeyPress(event: KeyboardEvent) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'g':
|
case 'g':
|
||||||
store.dispatch(toggleGrid());
|
store.dispatch(toggleGrid());
|
||||||
|
store.dispatch(notify((store.getState().gui.showGrid)
|
||||||
|
? t`Grid ON`
|
||||||
|
: t`Grid OFF`));
|
||||||
return;
|
return;
|
||||||
case 'h':
|
case 'h':
|
||||||
store.dispatch(toggleHistoricalView());
|
store.dispatch(toggleHistoricalView());
|
||||||
return;
|
return;
|
||||||
case 'x':
|
case 'x':
|
||||||
store.dispatch(togglePixelNotify());
|
store.dispatch(togglePixelNotify());
|
||||||
|
store.dispatch(notify((store.getState().gui.showPixelNotify)
|
||||||
|
? t`Pixel Notify ON`
|
||||||
|
: t`Pixel Notify OFF`));
|
||||||
return;
|
return;
|
||||||
case 'm':
|
case 'm':
|
||||||
store.dispatch(toggleMute());
|
store.dispatch(toggleMute());
|
||||||
|
store.dispatch(notify((store.getState().audio.mute)
|
||||||
|
? t`Muted Sound`
|
||||||
|
: t`Unmuted Sound`));
|
||||||
return;
|
return;
|
||||||
case 'r': {
|
case 'r': {
|
||||||
const state = store.getState();
|
const { hover } = store.getState().gui;
|
||||||
const { hover } = state.gui;
|
|
||||||
const text = hover.join('_');
|
const text = hover.join('_');
|
||||||
copy(text);
|
copy(text);
|
||||||
store.dispatch(notify(t`Copied!`));
|
store.dispatch(notify(t`Copied!`));
|
||||||
|
@ -61,6 +85,9 @@ function onKeyPress(event: KeyboardEvent) {
|
||||||
}
|
}
|
||||||
case 'p':
|
case 'p':
|
||||||
store.dispatch(toggleHiddenCanvases());
|
store.dispatch(toggleHiddenCanvases());
|
||||||
|
store.dispatch(notify((store.getState().canvas.showHiddenCanvases)
|
||||||
|
? t`Show Hidden Canvases`
|
||||||
|
: t`Hide Hidden Canvases`));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user