Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
To enable keyboard shortcuts of VS Code when the iframe is focused,
Browse files Browse the repository at this point in the history
we have to dispatch keyboard events in the parent window.
See microsoft/vscode#65452
Close James-Yu#1406.
  • Loading branch information
tamuratak committed Feb 14, 2020
1 parent a693907 commit 3c1e314
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ export class Viewer {
iframe.contentWindow.focus();
}, 100);
}
// To enable keyboard shortcuts of VS Code when the iframe is focused,
// we have to dispatch keyboard events in the parent window.
// See https://github.com/microsoft/vscode/issues/65452
window.addEventListener("message", (e) => {
window.dispatchEvent(new KeyboardEvent('keydown', e.data));
}, false);
</script>
</body></html>
`
Expand Down
20 changes: 20 additions & 0 deletions viewer/latexworkshop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
this.hidePrintButton()
this.registerKeybinding()
this.startConnectionKeeper()
this.startRebroadcastingKeyboardEvent()
}

onWillStartPdfViewer(cb: (e: Event) => any): IDisposable {
Expand Down Expand Up @@ -310,6 +311,25 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
}, 30000)
}

startRebroadcastingKeyboardEvent() {
if (!this.embedded) {
return
}
document.addEventListener('keydown', e => {
const obj = {
altKey: e.altKey,
code: e.code,
ctrlKey: e.ctrlKey,
isComposing: e.isComposing,
key: e.key,
location: e.location,
metaKey: e.metaKey,
repeat: e.repeat,
shiftKey: e.shiftKey
}
window.parent.postMessage(obj, '*')
})
}
}

new LateXWorkshopPdfViewer()

0 comments on commit 3c1e314

Please sign in to comment.