Skip to content

Commit

Permalink
Restore hot reload keyboard shortcut (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen authored Dec 8, 2024
1 parent ee5791e commit 4fc5e3f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mesop/web/src/editor/editor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component} from '@angular/core';
import {Component, HostListener} from '@angular/core';
import {
DefaultHotReloadWatcher,
HotReloadWatcher,
Expand All @@ -11,6 +11,8 @@ import {
ErrorDialogService,
} from '../services/error_dialog_service';
import {Shell, registerComponentRendererElement} from '../shell/shell';
import {isMac} from '../utils/platform';
import {Channel} from '../services/channel';
// Keep the following comment to ensure there's a hook for adding TS imports in the downstream sync.
// ADD_TS_IMPORT_HERE

Expand All @@ -23,8 +25,27 @@ import {Shell, registerComponentRendererElement} from '../shell/shell';
})
class Editor {
constructor(
private readonly channel: Channel,
private readonly hotReloadWatcher: HotReloadWatcher /* Inject hotReloadWatcher to ensure it's instantiated. */,
) {}

@HostListener('window:keydown', ['$event'])
handleKeyDown(event: KeyboardEvent) {
// Hotkey for hot reload
//
// Binds:
// cmd + shift + r (MacOs)
// ctrl + shift + r (Other platforms)
if (
event.key === 'r' &&
(isMac() ? event.metaKey : event.ctrlKey) &&
event.shiftKey
) {
this.channel.hotReload();
event.preventDefault();
return;
}
}
}

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

0 comments on commit 4fc5e3f

Please sign in to comment.