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(sheets): bugfix for freeze & hover-manager-service & data-validation #2233

Merged
merged 12 commits into from
May 15, 2024
Prev Previous commit
Next Next commit
fix: hover-manager-service
  • Loading branch information
weird94 committed May 13, 2024
commit ac6154c5374b44344367ea41831673384fd1c1da
54 changes: 34 additions & 20 deletions packages/sheets-ui/src/controllers/hover-render.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,57 @@
* limitations under the License.
*/

import type { Workbook } from '@univerjs/core';
import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { Nullable, Workbook } from '@univerjs/core';
import { Disposable, DisposableCollection, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { IRenderContext, IRenderController } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import { Inject } from '@wendellhu/redi';
import { HoverManagerService } from '../services/hover-manager.service';
import type { ISheetSkeletonManagerParam } from '../services/sheet-skeleton-manager.service';
import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';

@OnLifecycle(LifecycleStages.Rendered, HoverRenderController)
export class HoverRenderController extends Disposable implements IRenderController {
constructor(
private readonly _context: IRenderContext<Workbook>,
@IRenderManagerService private _renderManagerService: IRenderManagerService,
@Inject(HoverManagerService) private _hoverManagerService: HoverManagerService,
@IUniverInstanceService private _univerInstanceService: IUniverInstanceService
@Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService
) {
super();

this._initPointerEvent();
}

private _initPointerEvent() {
const currentRender = this._renderManagerService.getRenderById(
this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId()
);
if (!currentRender) {
return;
}

const { scene } = currentRender;
const observer = scene.onPointerMoveObserver.add((evt) => {
this._hoverManagerService.onMouseMove(evt.offsetX, evt.offsetY);
});

this.disposeWithMe({
dispose() {
scene.onPointerMoveObserver.remove(observer);
},
});
const disposeSet = new DisposableCollection();
const handleSkeletonChange = (skeletonParam: Nullable<ISheetSkeletonManagerParam>) => {
disposeSet.dispose();
if (!skeletonParam) {
return;
}

const currentRender = this._renderManagerService.getRenderById(skeletonParam.unitId);

if (!currentRender) {
return;
}

const { scene } = currentRender;
const observer = scene.onPointerMoveObserver.add((evt) => {
this._hoverManagerService.onMouseMove(evt.offsetX, evt.offsetY);
});

disposeSet.add({
dispose() {
scene.onPointerMoveObserver.remove(observer);
},
});
};

handleSkeletonChange(this._sheetSkeletonManagerService.getCurrent());
this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((skeletonParam) => {
handleSkeletonChange(skeletonParam);
}));
}
}
Loading