Skip to content

Commit

Permalink
fix: fix cmd+f in opensumi libro
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk committed Feb 19, 2025
1 parent 15242e8 commit 85409bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
LibroSearchToggleCommand,
LibroService,
LibroView,
NotebookCommands,
} from '@difizen/libro-jupyter';
import type { Container } from '@difizen/mana-app';
import { CommandRegistry as LibroCommandRegistry } from '@difizen/mana-app';
import { Autowired } from '@opensumi/di';
import type {
IContextKey,
KeybindingRegistry,
MaybePromise,
} from '@opensumi/ide-core-browser';
Expand Down Expand Up @@ -36,22 +38,33 @@ export class LibroKeybindContribution
protected readonly commandRegistry: CommandRegistry;
@Autowired(ManaContainer)
private readonly manaContainer: Container;
notebookFocusContext: IContextKey<boolean>;

initialize(): MaybePromise<void> {
this.registerContextKey();
}

onDidStart(): MaybePromise<void> {
this.libroService.onFocusChanged((e) => {
if (e instanceof LibroView) {
this.notebookFocusContext.set(true);
} else {
this.notebookFocusContext.set(false);
}
});
}

registerContextKey() {
const notebookFocusContext = this.contextKeyService.createKey<boolean>(
this.notebookFocusContext = this.contextKeyService.createKey<boolean>(
'libroNotebookFocused',
false,
this.hasActiveNotebook(),
);

this.workbenchEditorService.onActiveResourceChange((e) => {
if (e?.uri?.path.ext === `.${LIBRO_COMPONENTS_SCHEME_ID}`) {
notebookFocusContext.set(true);
this.notebookFocusContext.set(true);
} else {
notebookFocusContext.set(false);
this.notebookFocusContext.set(false);
}
});
}
Expand All @@ -64,6 +77,13 @@ export class LibroKeybindContribution
return this.manaContainer.get(LibroCommandRegistry);
}

hasActiveNotebook() {
return (
this.libroService.active instanceof LibroView &&
this.libroService.focus instanceof LibroView
);
}

registerCommands(commands: CommandRegistry) {
commands.registerCommand(NotebookCommands['EnterCommandMode'], {
execute: () => {
Expand Down
3 changes: 1 addition & 2 deletions archive/opensumi-module-libro/src/mana/editor/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CodeEditorModule } from '@difizen/libro-code-editor';
import { ManaModule } from '@difizen/mana-app';

import { LibroE2EditorContribution } from './editor-contribution';
import { Keybindhandler } from './keybind-handler';
import {
LibroOpensumiEditor,
LibroOpensumiEditorFactory,
Expand All @@ -12,7 +11,7 @@ import {
} from './opensumi-editor';

export const LibroOpensumiEditorModule = ManaModule.create()
.register(LibroE2EditorContribution, LibroOpensumiEditor, Keybindhandler, {
.register(LibroE2EditorContribution, LibroOpensumiEditor, {
token: LibroOpensumiEditorFactory,
useFactory: (ctx) => {
return (options: IEditorOptions, editorState: EditorState) => {
Expand Down

0 comments on commit 85409bd

Please sign in to comment.