Skip to content

Commit e2805fe

Browse files
authored
Merge pull request #14 from CodinGame/fix-keybinding-service-now-singleton
Fix keybinding service usage which is now a singleton
2 parents 5e87e70 + 4e98cff commit e2805fe

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingame/monaco-editor-wrapper",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"private": false,
55
"description": "Enhanced Monaco editor with TextMate grammars and more",
66
"scripts": {
@@ -24,7 +24,7 @@
2424
"dependencies": {
2525
"@codingame/monaco-emacs": "^0.2.3",
2626
"delay": ">=5.0.0",
27-
"monaco-editor": "npm:@codingame/monaco-editor@^0.32.0",
27+
"monaco-editor": "npm:@codingame/monaco-editor@^0.32.1",
2828
"monaco-vim": "^0.2.0",
2929
"vscode-oniguruma": "^1.6.1"
3030
},

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)