Skip to content

Commit 4fc5e3f

Browse files
authored
Restore hot reload keyboard shortcut (#1140)
1 parent ee5791e commit 4fc5e3f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

mesop/web/src/editor/editor.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component} from '@angular/core';
1+
import {Component, HostListener} from '@angular/core';
22
import {
33
DefaultHotReloadWatcher,
44
HotReloadWatcher,
@@ -11,6 +11,8 @@ import {
1111
ErrorDialogService,
1212
} from '../services/error_dialog_service';
1313
import {Shell, registerComponentRendererElement} from '../shell/shell';
14+
import {isMac} from '../utils/platform';
15+
import {Channel} from '../services/channel';
1416
// Keep the following comment to ensure there's a hook for adding TS imports in the downstream sync.
1517
// ADD_TS_IMPORT_HERE
1618

@@ -23,8 +25,27 @@ import {Shell, registerComponentRendererElement} from '../shell/shell';
2325
})
2426
class Editor {
2527
constructor(
28+
private readonly channel: Channel,
2629
private readonly hotReloadWatcher: HotReloadWatcher /* Inject hotReloadWatcher to ensure it's instantiated. */,
2730
) {}
31+
32+
@HostListener('window:keydown', ['$event'])
33+
handleKeyDown(event: KeyboardEvent) {
34+
// Hotkey for hot reload
35+
//
36+
// Binds:
37+
// cmd + shift + r (MacOs)
38+
// ctrl + shift + r (Other platforms)
39+
if (
40+
event.key === 'r' &&
41+
(isMac() ? event.metaKey : event.ctrlKey) &&
42+
event.shiftKey
43+
) {
44+
this.channel.hotReload();
45+
event.preventDefault();
46+
return;
47+
}
48+
}
2849
}
2950

3051
const routes: Routes = [{path: '**', component: Editor}];

0 commit comments

Comments
 (0)