Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clipboard deps #4115

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading