Skip to content

Commit 50dcecd

Browse files
zhanbahacke2
andauthored
fix: restored notebook have invalid keybinding (#4174)
Co-authored-by: hacke2 <[email protected]>
1 parent c44ba38 commit 50dcecd

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

packages/notebook/src/browser/libro-keybind-contribution.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1-
import { LibroSearchToggleCommand, LibroService, LibroView, NotebookCommands } from '@difizen/libro-jupyter/noeditor';
1+
import { LibroSearchToggleCommand, LibroService, NotebookCommands } from '@difizen/libro-jupyter/noeditor';
22
import { Container, CommandRegistry as LibroCommandRegistry } from '@difizen/mana-app';
33

44
import { Autowired } from '@opensumi/di';
55
import {
66
ClientAppContribution,
7+
CommandContribution,
78
CommandRegistry,
89
Domain,
910
IContextKeyService,
11+
KeybindingContribution,
1012
KeybindingRegistry,
1113
KeybindingScope,
14+
MaybePromise,
1215
} from '@opensumi/ide-core-browser';
1316
import { WorkbenchEditorService } from '@opensumi/ide-editor';
1417

1518
import { LIBRO_COMPONENTS_SCHEME_ID } from './libro.protocol';
1619
import { ManaContainer } from './mana';
1720

18-
@Domain(ClientAppContribution)
19-
export class LibroKeybindContribution implements ClientAppContribution {
21+
@Domain(ClientAppContribution, KeybindingContribution, CommandContribution)
22+
export class LibroKeybindContribution implements ClientAppContribution, KeybindingContribution, CommandContribution {
2023
@Autowired(IContextKeyService) contextKeyService: IContextKeyService;
21-
@Autowired(KeybindingRegistry) keybindingRegistry: KeybindingRegistry;
2224
@Autowired(WorkbenchEditorService)
2325
workbenchEditorService: WorkbenchEditorService;
2426
@Autowired(CommandRegistry)
2527
protected readonly commandRegistry: CommandRegistry;
2628
@Autowired(ManaContainer)
2729
private readonly manaContainer: Container;
2830

29-
onStart() {
31+
initialize(): MaybePromise<void> {
3032
this.registerContextKey();
31-
this.registerCommand();
32-
this.registerKeybind();
3333
}
3434

3535
registerContextKey() {
36-
const notebookFocusContext = this.contextKeyService.createKey<boolean>(
37-
'libroNotebookFocused',
38-
this.hasActiveNotebook(),
39-
);
36+
const notebookFocusContext = this.contextKeyService.createKey<boolean>('libroNotebookFocused', false);
4037

4138
this.workbenchEditorService.onActiveResourceChange((e) => {
4239
if (e?.uri?.path.ext === `.${LIBRO_COMPONENTS_SCHEME_ID}`) {
@@ -55,45 +52,41 @@ export class LibroKeybindContribution implements ClientAppContribution {
5552
return this.manaContainer.get(LibroCommandRegistry);
5653
}
5754

58-
hasActiveNotebook() {
59-
return this.libroService.active instanceof LibroView;
60-
}
61-
62-
registerCommand() {
63-
this.commandRegistry.registerCommand(NotebookCommands['EnterCommandMode'], {
55+
registerCommands(commands: CommandRegistry) {
56+
commands.registerCommand(NotebookCommands['EnterCommandMode'], {
6457
execute: () => {
6558
this.libroCommandRegistry.executeCommand(NotebookCommands['EnterCommandMode'].id);
6659
},
6760
});
68-
this.commandRegistry.registerCommand(NotebookCommands['RunCell'], {
61+
commands.registerCommand(NotebookCommands['RunCell'], {
6962
execute: () => {
7063
this.libroCommandRegistry.executeCommand(NotebookCommands['RunCell'].id);
7164
},
7265
});
73-
this.commandRegistry.registerCommand(NotebookCommands['RunCellAndSelectNext'], {
66+
commands.registerCommand(NotebookCommands['RunCellAndSelectNext'], {
7467
execute: () => {
7568
this.libroCommandRegistry.executeCommand(NotebookCommands['RunCellAndSelectNext'].id);
7669
},
7770
});
78-
this.commandRegistry.registerCommand(NotebookCommands['RunCellAndInsertBelow'], {
71+
commands.registerCommand(NotebookCommands['RunCellAndInsertBelow'], {
7972
execute: () => {
8073
this.libroCommandRegistry.executeCommand(NotebookCommands['RunCellAndInsertBelow'].id);
8174
},
8275
});
83-
this.commandRegistry.registerCommand(NotebookCommands['SplitCellAntCursor'], {
76+
commands.registerCommand(NotebookCommands['SplitCellAntCursor'], {
8477
execute: () => {
8578
this.libroCommandRegistry.executeCommand(NotebookCommands['SplitCellAntCursor'].id);
8679
},
8780
});
88-
this.commandRegistry.registerCommand(LibroSearchToggleCommand.ShowLibroSearch, {
81+
commands.registerCommand(LibroSearchToggleCommand.ShowLibroSearch, {
8982
execute: () => {
9083
this.libroCommandRegistry.executeCommand(LibroSearchToggleCommand.ShowLibroSearch.id);
9184
},
9285
});
9386
}
9487

95-
registerKeybind() {
96-
this.keybindingRegistry.registerKeybindings(
88+
registerKeybindings(keybindings: KeybindingRegistry): void {
89+
keybindings.registerKeybindings(
9790
[
9891
{
9992
keybinding: 'f1',

packages/notebook/src/browser/libro/libro-opensumi-content-contribution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ContentLoaderType, OpensumiInjector } from '../mana';
1313
export class LibroOpensumiContentContribution implements ContentContribution {
1414
@inject(OpensumiInjector) injector: Injector;
1515

16-
canHandle = (options) => options.loadType === ContentLoaderType ? 100 : 1;
16+
canHandle = (options) => (options.loadType === ContentLoaderType ? 100 : 1);
1717
async loadContent(options: NotebookOption, model: LibroJupyterModel) {
1818
const fileServiceClient: IFileServiceClient = this.injector.get(IFileServiceClient);
1919
const messageService = this.injector.get(IMessageService);
@@ -33,7 +33,8 @@ export class LibroOpensumiContentContribution implements ContentContribution {
3333
}
3434
const uri = new URI(options.resource.toString());
3535
const currentFileContents: IContentsModel = {
36-
name: uri.path.name,
36+
name: uri.path.base,
37+
// TODO: should be relative path to notebook root, notebook root may not be same as ide root, and jupyter provide no api to get root dir
3738
path: uri.path.toString(),
3839
last_modified: stat?.lastModification.toString() || new Date().toJSON(),
3940
created: stat?.createTime?.toString() || new Date().toJSON(),

0 commit comments

Comments
 (0)