File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/comm
20
20
import ts from 'typescript'
21
21
import { watchEffect } from 'vue'
22
22
import { isDark } from '../logic/dark'
23
+ import { lockShortcuts , unlockShortcuts } from '../state'
23
24
24
25
window . MonacoEnvironment = {
25
26
getWorker ( _ , label ) {
@@ -97,6 +98,16 @@ const setup = createSingletonPromise(async () => {
97
98
Object . assign ( editorOptions , result ?. editorOptions )
98
99
}
99
100
101
+ // Disable shortcuts when focusing Monaco editor.
102
+ monaco . editor . onDidCreateEditor ( ( editor ) => {
103
+ editor . onDidFocusEditorWidget ( ( ) => {
104
+ lockShortcuts ( )
105
+ } )
106
+ editor . onDidBlurEditorWidget ( ( ) => {
107
+ unlockShortcuts ( )
108
+ } )
109
+ } )
110
+
100
111
// Use Shiki to highlight Monaco
101
112
shikiToMonaco ( highlighter , monaco )
102
113
if ( typeof themes === 'string' ) {
Original file line number Diff line number Diff line change @@ -15,7 +15,30 @@ export const showOverview = ref(false)
15
15
export const hmrSkipTransition = ref ( false )
16
16
export const disableTransition = ref ( false )
17
17
18
- export const shortcutsEnabled = ref ( true )
18
+ const mutableShortcutsEnabled = ref ( true )
19
+ /**
20
+ * Whether the keyboard shortcuts are enabled. Readonly,
21
+ * use `lockShortcuts` and `unlockShortcuts` to modify.
22
+ */
23
+ export const shortcutsEnabled = computed ( ( ) => mutableShortcutsEnabled . value )
24
+
25
+ // Use a lock counter to support multiple simultaneous locks
26
+ // and avoid race conditions. Race conditions may occur, for example,
27
+ // when locking shortcuts on editor focus and moving from one editor
28
+ // to another, as blur events can be triggered after focus.
29
+ let shortcutsLockCounter = 0
30
+ export function lockShortcuts ( ) {
31
+ shortcutsLockCounter ++
32
+ mutableShortcutsEnabled . value = false
33
+ }
34
+ export function unlockShortcuts ( ) {
35
+ shortcutsLockCounter --
36
+ if ( shortcutsLockCounter <= 0 ) {
37
+ shortcutsLockCounter = 0
38
+ mutableShortcutsEnabled . value = true
39
+ }
40
+ }
41
+
19
42
export const breakpoints = useBreakpoints ( {
20
43
xs : 460 ,
21
44
...breakpointsTailwind ,
You can’t perform that action at this time.
0 commit comments