Skip to content

Commit

Permalink
Disable Reveal shortcuts when drop is active
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Jul 24, 2024
1 parent 028c487 commit 26ac724
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 41 deletions.
75 changes: 40 additions & 35 deletions _extensions/drop/drop-runtime.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions drop-runtime/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions drop-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@lezer/python": "^1.1.14",
"codemirror": "^6.0.1",
"codemirror-lang-r": "^0.1.0-2",
"keycode": "^2.2.1",
"lezer-r": "^0.1.1",
"xterm": "^5.3.0"
}
Expand Down
30 changes: 24 additions & 6 deletions drop-runtime/src/drop-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import "./drop-runtime.css";
import keycode from 'keycode';
import { startWebRApp, startPyodideApp } from './App';

declare global {
interface Window {
Reveal: any;
RevealDrop?: any;
RevealDrop?: {
id: string;
dropElement: HTMLDivElement;
init: (reveal: any) => void;
toggleDrop: () => void;
isActive: () => boolean;
};
}
}

Expand All @@ -27,11 +34,9 @@ type DropConfig = {
window.RevealDrop = window.RevealDrop || {
id: 'RevealDrop',
dropElement: document.createElement('div'),
config: {},
init: function() {
// Configuration
const config = window.Reveal.getConfig().drop as DropConfig;
window.RevealDrop.config = config;
init: function (reveal) {
const revealConfig = reveal.getConfig();
const config = revealConfig.drop as DropConfig;

// Add Drop down panel to DOM
const drop = window.RevealDrop.dropElement;
Expand Down Expand Up @@ -67,15 +72,28 @@ window.RevealDrop = window.RevealDrop || {
}

// Keyboard listeners
reveal.addKeyBinding({
keyCode: keycode(config.shortcut),
key: config.shortcut,
description: 'Toggle console'
}, () => {});

document.addEventListener("keydown", (event) => {
if (event.key == config.shortcut && !event.altKey) {
window.RevealDrop.toggleDrop();
reveal.toggleHelp(false);
reveal.toggleOverview(false);
reveal.configure({ keyboard: !window.RevealDrop.isActive() });
event.preventDefault();
event.stopPropagation();
}
}, { capture: true });

},
toggleDrop() {
window.RevealDrop.dropElement.classList.toggle("active");
},
isActive() {
return window.RevealDrop.dropElement.classList.contains("active");
}
};

0 comments on commit 26ac724

Please sign in to comment.