Skip to content

Commit

Permalink
fix: highlight not work when select link (#2978)
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 authored Aug 8, 2024
1 parent c1a342d commit 6a97ced
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentDataModel>,
@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() {
Expand All @@ -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);
}
}
}));
}
}

0 comments on commit 6a97ced

Please sign in to comment.