Skip to content

Commit 9fc2aac

Browse files
committed
feat: Export 2 distinct function to update keybinding and keybinding mode
1 parent 337e25b commit 9fc2aac

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createEditor, registerEditorOpenHandler, registerTextModelContentProvid
33
import { addVSCodeTheme } from './theme'
44
import { updateUserConfiguration, registerConfigurations, registerDefaultConfigurations, onConfigurationChanged, getConfiguration } from './configuration'
55
import { getMonacoLanguage } from './languages'
6-
import { updateEditorKeybindings } from './keybindings'
6+
import { updateKeybindings, updateEditorKeybindingsMode } from './keybindings'
77
import { getThemeData } from './theme/registry'
88
import type { IVSCodeTheme } from './theme/tools'
99

@@ -21,7 +21,8 @@ export {
2121
updateUserConfiguration,
2222
getConfiguration,
2323
onConfigurationChanged,
24-
updateEditorKeybindings,
24+
updateEditorKeybindingsMode,
25+
updateKeybindings,
2526

2627
getMonacoLanguage,
2728
registerTextModelContentProvider,

src/keybindings/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as monaco from 'monaco-editor'
22
import EmacsExtension from '@codingame/monaco-emacs'
3-
import { updateKeybindings } from './keybindingHelper'
43
import { initVimMode } from './vim'
54

6-
export function updateEditorKeybindings (
5+
const keybindingService = monaco.extra.StandaloneServices.get(monaco.extra.IKeybindingService) as monaco.extra.StandaloneKeybindingService
6+
7+
export function updateKeybindings (bindings: monaco.extra.IUserFriendlyKeybinding[]): void {
8+
keybindingService.setUserKeybindings(bindings)
9+
}
10+
11+
export function updateEditorKeybindingsMode (
712
editor: monaco.editor.IStandaloneCodeEditor,
813
keyBindingsMode: 'classic' | 'vim' | 'emacs' = 'classic',
9-
statusBarElement: Element,
10-
keyBindings?: monaco.extra.IUserFriendlyKeybinding[]
14+
statusBarElement: Element
1115
): monaco.IDisposable {
1216
switch (keyBindingsMode) {
1317
case 'vim': {
@@ -19,11 +23,8 @@ export function updateEditorKeybindings (
1923
return emacsExtension
2024
}
2125
default: {
22-
updateKeybindings(editor, keyBindings ?? [])
2326
return {
24-
dispose: () => {
25-
updateKeybindings(editor, [])
26-
}
27+
dispose: () => {}
2728
}
2829
}
2930
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as monaco from 'monaco-editor'
22

3-
export function updateKeybindings (editor: monaco.editor.IStandaloneCodeEditor, bindings: monaco.extra.IUserFriendlyKeybinding[]): void {
4-
(editor as monaco.editor.StandaloneCodeEditor)._standaloneKeybindingService!.setUserKeybindings(bindings)
3+
const keybindingService = monaco.extra.StandaloneServices.get(monaco.extra.IKeybindingService) as monaco.extra.StandaloneKeybindingService
4+
5+
export function updateKeybindings (bindings: monaco.extra.IUserFriendlyKeybinding[]): void {
6+
keybindingService.setUserKeybindings(bindings)
57
}

0 commit comments

Comments
 (0)