Skip to content

Commit

Permalink
Merge pull request #107 from Turbinya/navigation_with_additional_mous…
Browse files Browse the repository at this point in the history
…e_keys

feat(shortcuts): navigation with additional mouse keys (#58)
  • Loading branch information
kimlimjustin authored Oct 1, 2021
2 parents a9267f4 + f8036b1 commit bd00db1
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Components/Shortcut/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const changeSelectedStatus = (): void => {
const Shortcut = (): void => {
const { reload, minimize, maximize } = require('../Layout/windowManager'); //eslint-disable-line
const { createNewTab, goBack, goForward } = require('../Layout/tab'); //eslint-disable-line
const ShortcutHandler = (e: KeyboardEvent) => {

const KeyboardShortcutsHandler = (e: KeyboardEvent) => {
e.preventDefault();
const selectedFilePath = unescape(getSelected()?.[0]?.dataset?.path);
const isDir = getSelected()?.[0]?.dataset.isdir === 'true';
Expand Down Expand Up @@ -278,9 +279,28 @@ const Shortcut = (): void => {
Redo();
}
};
document.addEventListener('keyup', ShortcutHandler);

const MouseShortcutsHandler = (e: MouseEvent) => {
// Don't react if cursor is over path navigator
if (document.querySelector('.path-navigator') === document.activeElement) return;

switch (e.button) {
// Back button
case 3:
goBack();
break;
// Forward button
case 4:
goForward();
}
}

document.addEventListener('keyup', KeyboardShortcutsHandler);
document.addEventListener('mouseup', MouseShortcutsHandler);

window.addEventListener('beforeunload', () => {
document.removeEventListener('keyup', ShortcutHandler, false);
document.removeEventListener('keyup', KeyboardShortcutsHandler, false);
document.addEventListener('mouseup', MouseShortcutsHandler);
});
};

Expand Down

1 comment on commit bd00db1

@vercel
Copy link

@vercel vercel bot commented on bd00db1 Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.