Skip to content

Commit

Permalink
fix: clipboard deps (#4115)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku authored Nov 29, 2024
1 parent de4d70b commit 57c595e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ export class SheetClipboardController extends RxDisposable {
super();
this._init();
this._initCommandListener();
this._pasteWithDoc();
}

const docSelectionRenderService = this._renderManagerService.getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY)?.with(DocSelectionRenderService);

if (docSelectionRenderService) {
private _pasteWithDoc() {
const sheetPasteShortKeyFn = (docSelectionRenderService: DocSelectionRenderService) => {
docSelectionRenderService.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
if (!whenSheetEditorFocused(this._contextService)) {
return;
Expand All @@ -141,7 +142,25 @@ export class SheetClipboardController extends RxDisposable {
const textContent = clipboardEvent.clipboardData?.getData('text/plain');
this._commandService.executeCommand(SheetPasteShortKeyCommand.id, { htmlContent, textContent });
});
};

// docSelectionRenderService would init before clipboardService controller when creating a univer.
// But when creating a sheet unit again after the previous sheet unit has been disposed, clipboard controller would init before docSelectionRenderService.
// In this case, DocSelectionRenderService isn't ready when clipboardService controller init.
// So better listening to the created$ event of the renderManagerService to get the DocSelectionRenderService instance.
let docSelectionRenderService = this._renderManagerService.getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY)?.with(DocSelectionRenderService);

if (docSelectionRenderService) {
sheetPasteShortKeyFn(docSelectionRenderService);
}
this._renderManagerService.created$.subscribe((renderer) => {
if (renderer.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
docSelectionRenderService = this._renderManagerService.getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY)?.with(DocSelectionRenderService);
if (docSelectionRenderService) {
sheetPasteShortKeyFn(docSelectionRenderService);
}
}
});
}

private _init(): void {
Expand Down
5 changes: 4 additions & 1 deletion packages/sheets-ui/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class UniverSheetsUIPlugin extends Plugin {
[AutoHeightController],
[AutoWidthController],
[FormulaEditorController],
[SheetClipboardController],
[SheetsRenderService],
[SheetUIController],
[StatusBarController],
Expand Down Expand Up @@ -170,6 +169,10 @@ export class UniverSheetsUIPlugin extends Plugin {
this._initAutoFocus();
}

registerDependencies(this._injector, [
[SheetClipboardController],
]);

this._registerRenderBasics();

touchDependencies(this._injector, [
Expand Down

0 comments on commit 57c595e

Please sign in to comment.