Skip to content

Commit 0801eed

Browse files
committed
fix: prevent hotkeys when typing in monaco editor
1 parent c87d474 commit 0801eed

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/client/setup/monaco.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import setups from '#slidev/setups/monaco'
44
import { createSingletonPromise } from '@antfu/utils'
55
import { setupTypeAcquisition } from '@typescript/ata'
66
import * as monaco from 'monaco-editor'
7-
87
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
98
// @ts-expect-error missing types
109
import { StandaloneServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices'
@@ -16,10 +15,10 @@ import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
1615
import { ContextViewService } from 'monaco-editor/esm/vs/platform/contextview/browser/contextViewService'
1716
// @ts-expect-error missing types
1817
import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors'
19-
2018
import ts from 'typescript'
2119
import { watchEffect } from 'vue'
2220
import { isDark } from '../logic/dark'
21+
import { shortcutsEnabled } from '../state'
2322

2423
window.MonacoEnvironment = {
2524
getWorker(_, label) {
@@ -97,6 +96,18 @@ const setup = createSingletonPromise(async () => {
9796
Object.assign(editorOptions, result?.editorOptions)
9897
}
9998

99+
// Disable shortcuts when focusing Monaco editor.
100+
monaco.editor.onDidCreateEditor((editor) => {
101+
let areShortcutsEnabled = shortcutsEnabled.value
102+
editor.onDidFocusEditorWidget(() => {
103+
areShortcutsEnabled = shortcutsEnabled.value
104+
shortcutsEnabled.value = false
105+
})
106+
editor.onDidBlurEditorWidget(() => {
107+
shortcutsEnabled.value = areShortcutsEnabled
108+
})
109+
})
110+
100111
// Use Shiki to highlight Monaco
101112
shikiToMonaco(highlighter, monaco)
102113
if (typeof themes === 'string') {

0 commit comments

Comments
 (0)