Skip to content

Commit

Permalink
fix: docSelectionRenderService listening to _renderManagerService.cre…
Browse files Browse the repository at this point in the history
…ated$
  • Loading branch information
lumixraku committed Nov 21, 2024
1 parent d821575 commit 77a3afb
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,11 @@ export class SheetClipboardController extends RxDisposable {
super();
this._init();
this._initCommandListener();
setTimeout(() => {
this._pasteWithDoc();
}, 0);
this._pasteWithDoc();
}

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

console.log('SheetClipboardController init doc selection service', docSelectionRenderService);
if (docSelectionRenderService) {
const sheetPasteShortKeyFn = (docSelectionRenderService: DocSelectionRenderService) => {
docSelectionRenderService.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
if (!whenSheetEditorFocused(this._contextService)) {
return;
Expand All @@ -147,6 +142,29 @@ 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) {
// console.log('SheetClipboardController init doc selection service', docSelectionRenderService);
sheetPasteShortKeyFn(docSelectionRenderService);
} else {
// console.log('SheetClipboardController init doc selection service DOCS_NORMAL_EDITOR_UNIT_ID_KEY', DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
this._renderManagerService.created$.subscribe((renderer) => {
if (renderer.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
console.log('SheetClipboardController init doc selection service $$$$', renderer);

Check failure on line 160 in packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement
docSelectionRenderService = this._renderManagerService.getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY)?.with(DocSelectionRenderService);
console.log('SheetClipboardController init doc selection service $$$$$', docSelectionRenderService);

Check failure on line 162 in packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement
if (docSelectionRenderService) {
sheetPasteShortKeyFn(docSelectionRenderService);
}
}
});
}
}

Expand Down

0 comments on commit 77a3afb

Please sign in to comment.