Skip to content

Commit f7a25a3

Browse files
patrikholcakCompuIves
authored andcommitted
Add support for native keyboard shortcuts in fullscreen (codesandbox#2716)
1 parent 8b379a0 commit f7a25a3

File tree

1 file changed

+52
-15
lines changed

1 file changed

+52
-15
lines changed

packages/app/src/app/vscode/index.ts

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {
2-
convertTypeToStatus,
3-
notificationState,
4-
} from '@codesandbox/common/lib/utils/notifications';
1+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
52
import { blocker } from 'app/utils/blocker';
6-
import { NotificationMessage } from '@codesandbox/notifications/lib/state';
3+
import {
4+
NotificationMessage,
5+
NotificationStatus,
6+
} from '@codesandbox/notifications/lib/state';
77

88
import { KeyCode, KeyMod } from './keyCodes';
99
import bootstrap from './dev-bootstrap';
@@ -113,6 +113,42 @@ class VSCodeManager {
113113
},
114114
});
115115

116+
this.addWorkbenchAction({
117+
id: 'view.fullscreen',
118+
label: 'Toggle Fullscreen',
119+
category: 'View',
120+
run: () => {
121+
if (document.fullscreenElement) {
122+
document.exitFullscreen();
123+
} else {
124+
document.documentElement.requestFullscreen();
125+
126+
this.addNotification({
127+
title: 'Fullscreen',
128+
message:
129+
'You are now in fullscreen mode. Press and hold ESC to exit',
130+
status: NotificationStatus.NOTICE,
131+
timeAlive: 5000,
132+
});
133+
134+
if ('keyboard' in navigator) {
135+
// @ts-ignore - keyboard locking is experimental api
136+
navigator.keyboard.lock([
137+
'Escape',
138+
'KeyW',
139+
'KeyN',
140+
'KeyT',
141+
'ArrowLeft',
142+
'ArrowRight',
143+
]);
144+
}
145+
}
146+
},
147+
keybindings: {
148+
primary: KeyMod.WinCtrl | KeyMod.Alt | KeyCode.KEY_F,
149+
},
150+
});
151+
116152
this.appendMenuItem(MenuId.MenubarFileMenu, {
117153
group: '1_new',
118154
order: 1,
@@ -159,6 +195,15 @@ class VSCodeManager {
159195
order: 2,
160196
});
161197

198+
this.appendMenuItem(MenuId.MenubarViewMenu, {
199+
group: '1_toggle_view',
200+
order: 0,
201+
command: {
202+
id: 'view.fullscreen',
203+
title: 'Toggle Fullscreen',
204+
},
205+
});
206+
162207
const addBrowserNavigationCommand = (
163208
id: string,
164209
label: string,
@@ -304,16 +349,8 @@ class VSCodeManager {
304349
});
305350
}
306351

307-
addNotification(
308-
message: string,
309-
type: 'warning' | 'notice' | 'error' | 'success',
310-
notification: NotificationMessage
311-
) {
312-
notificationState.addNotification({
313-
message,
314-
status: convertTypeToStatus(type),
315-
...notification,
316-
});
352+
addNotification(notification: NotificationMessage) {
353+
notificationState.addNotification(notification);
317354
}
318355

319356
/**

0 commit comments

Comments
 (0)