Skip to content

Commit

Permalink
fix editor alt+m focus trap (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
YingXue authored Dec 18, 2024
1 parent ca7301b commit 55c38b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-iot-explorer",
"version": "0.15.11",
"version": "0.15.12",
"description": "This project welcomes contributions and suggestions. Most contributions require you to agree to a\r Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\r the rights to use your contribution. For details, visit https://cla.microsoft.com.",
"main": "host/electron.js",
"build": {
Expand Down
17 changes: 17 additions & 0 deletions src/app/shared/components/monacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ export const MonacoEditorComponent: React.FC<MonacoEditorComponentProps> = ({
editorDidMount={(editor): void => {
editorRef.current = editor;
placeholderContentWidget(editor, placeholder || '');

editor.addCommand(
monaco.KeyMod.Alt | monaco.KeyCode.KeyM,
() => {

/* In Electron, to fully remove focus from the Monaco Editor.
we will need to shift focus to another DOM element or window.
It is due to Electron's integration with Chromium and the way focus is managed between the webview and the main process.
We will create a dummy input, move the focus to it, and then clean it up. */
const dummyInput = document.createElement("input");
dummyInput.style.position = "absolute";
dummyInput.style.opacity = "0";
document.body.appendChild(dummyInput);
dummyInput.focus();
setTimeout(() => document.body.removeChild(dummyInput), 0);
}
);
}}
value={content}
language={language || 'json'}
Expand Down

0 comments on commit 55c38b8

Please sign in to comment.