diff --git a/packages/docs-hyper-link-ui/src/controllers/render-controllers/render.controller.ts b/packages/docs-hyper-link-ui/src/controllers/render-controllers/render.controller.ts index 5840b999ebb..e623aa59df9 100644 --- a/packages/docs-hyper-link-ui/src/controllers/render-controllers/render.controller.ts +++ b/packages/docs-hyper-link-ui/src/controllers/render-controllers/render.controller.ts @@ -18,17 +18,21 @@ import type { DocumentDataModel } from '@univerjs/core'; import { Disposable, Inject } from '@univerjs/core'; import type { IRenderContext, IRenderModule } from '@univerjs/engine-render'; import { DOC_INTERCEPTOR_POINT, DocInterceptorService } from '@univerjs/docs'; +import { DocRenderController } from '@univerjs/docs-ui'; +import { distinctUntilChanged, pairwise } from 'rxjs'; import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service'; export class DocHyperLinkRenderController extends Disposable implements IRenderModule { constructor( private readonly _context: IRenderContext, @Inject(DocInterceptorService) private readonly _docInterceptorService: DocInterceptorService, - @Inject(DocHyperLinkPopupService) private readonly _hyperLinkService: DocHyperLinkPopupService + @Inject(DocHyperLinkPopupService) private readonly _hyperLinkService: DocHyperLinkPopupService, + @Inject(DocRenderController) private readonly _docRenderController: DocRenderController ) { super(); this._init(); + this._initReRender(); } private _init() { @@ -49,4 +53,23 @@ export class DocHyperLinkRenderController extends Disposable implements IRenderM }, }); } + + private _initReRender() { + this.disposeWithMe(this._hyperLinkService.showingLink$ + .pipe( + distinctUntilChanged((prev, aft) => prev?.linkId === aft?.linkId && prev?.unitId === aft?.unitId), + pairwise() + ) + .subscribe(([preLink, link]) => { + if (link) { + if (link.unitId === this._context.unitId) { + this._docRenderController.reRender(link.unitId); + } + } else { + if (preLink && preLink.unitId === this._context.unitId) { + this._docRenderController.reRender(preLink.unitId); + } + } + })); + } }