Skip to content

Commit

Permalink
Ignore keyboard commands if the editor is not in focus
Browse files Browse the repository at this point in the history
  • Loading branch information
marian42 committed Feb 10, 2024
1 parent 66c48ba commit e686f35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ html, body {
height: 100%;
}

.canvas-container canvas:focus {
outline: none;
}

.canvas-container {
padding-left: 420px;
box-sizing: border-box;
width: 100%;
height: 100%;
height: 100%;
}

.sidebar {
Expand Down
4 changes: 3 additions & 1 deletion src/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Editor {
this.editorState = new EditorState();

this.canvas = document.getElementById('canvas') as HTMLCanvasElement;
this.canvas.tabIndex = 0;
this.camera = new Camera(this.canvas);

this.partRenderer = new MeshRenderer();
Expand Down Expand Up @@ -220,6 +221,7 @@ class Editor {
}

private onMouseDown(event: MouseEvent) {
this.canvas.focus();
const {ctrlKey, shiftKey} = event;
if (event.button === 0 && !ctrlKey && !shiftKey) {
if (this.handles.onMouseDown(event)) {
Expand Down Expand Up @@ -287,7 +289,7 @@ class Editor {
'Delete': () => this.remove(),
};

if (keyActions[event.key]) {
if (event.key in keyActions && document.activeElement == this.canvas) {
keyActions[event.key]();
}
}
Expand Down

0 comments on commit e686f35

Please sign in to comment.