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
feat: auto-height
  • Loading branch information
weird94 committed May 13, 2024
commit 7040ed1b7d298208a2c577f74a052234728d345f
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DataValidationRenderMode, DataValidationStatus, DataValidationType, IUn
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import { Inject, Injector } from '@wendellhu/redi';
import { IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { AutoHeightController, IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import type { Spreadsheet } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';
Expand Down Expand Up @@ -58,7 +58,8 @@ export class DataValidationRenderController extends RxDisposable {
@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,
@Inject(DataValidationDropdownManagerService) private readonly _dropdownManagerService: DataValidationDropdownManagerService,
@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,
@Inject(Injector) private readonly _injector: Injector
@Inject(Injector) private readonly _injector: Injector,
@Inject(AutoHeightController) private readonly _autoHeightController: AutoHeightController
) {
super();
this._init();
Expand All @@ -70,6 +71,7 @@ export class DataValidationRenderController extends RxDisposable {
this._initSkeletonChange();
this._initDropdown();
this._initViewModelIntercept();
this._initAutoHeight();
}

private _initMenu() {
Expand Down Expand Up @@ -204,7 +206,7 @@ export class DataValidationRenderController extends RxDisposable {
this._sheetInterceptorService.intercept(
INTERCEPTOR_POINT.CELL_CONTENT,
{
// eslint-disable-next-line max-lines-per-function
// eslint-disable-next-line max-lines-per-function, complexity
handler: (cell, pos, next) => {
const { row, col, unitId, subUnitId } = pos;
const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
Expand Down Expand Up @@ -328,4 +330,14 @@ export class DataValidationRenderController extends RxDisposable {
)
);
}

private _initAutoHeight() {
this.disposeWithMe(
this._dataValidationModel.ruleChange$.subscribe((payload) => {
if (payload.rule) {
this._autoHeightController.markRangeAutoHeightDirty(payload.rule.ranges);
}
})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export class CheckboxRender implements IBaseDataValidationWidget {
@Inject(ThemeService) private readonly _themeService: ThemeService
) {}

calcCellAutoHeight(): number | undefined {
return undefined;
calcCellAutoHeight(info: ICellRenderContext): number | undefined {
const { style } = info;
return (style?.fs ?? 10) * 1.6;
}

private async _parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult> {
Expand Down Expand Up @@ -163,6 +164,7 @@ export class CheckboxRender implements IBaseDataValidationWidget {
return false;
}


async onPointerDown(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
if (evt.button === 2) {
return;
Expand Down
29 changes: 21 additions & 8 deletions packages/sheets-ui/src/controllers/auto-height.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { IRange, Workbook } from '@univerjs/core';
import { IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type {
ISetRangeValuesRangeMutationParams,
ISetStyleCommandParams,
Expand All @@ -33,17 +33,22 @@ import {
} from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';

import { Subject } from 'rxjs';
import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';

@OnLifecycle(LifecycleStages.Ready, AutoHeightController)
export class AutoHeightController {
export class AutoHeightController extends Disposable {
private _autoHeightDirtyRanges$ = new Subject<IRange[]>();
autoHeightDirtyRanges$ = this._autoHeightDirtyRanges$.asObservable();

constructor(
@Inject(Injector) private _injector: Injector,
@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
@Inject(SelectionManagerService) private _selectionManagerService: SelectionManagerService,
@Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
@Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService
) {
super();
this._initialize();
}

Expand Down Expand Up @@ -92,7 +97,7 @@ export class AutoHeightController {
const { _sheetInterceptorService: sheetInterceptorService, _selectionManagerService: selectionManagerService } =
this;
// for intercept'SetRangeValuesCommand' command.
sheetInterceptorService.interceptCommand({
this.disposeWithMe(sheetInterceptorService.interceptCommand({
getMutations: (command: { id: string; params: ISetRangeValuesRangeMutationParams }) => {
if (command.id !== SetRangeValuesCommand.id) {
return {
Expand All @@ -103,9 +108,9 @@ export class AutoHeightController {

return this._getUndoRedoParamsOfAutoHeight(command.params.range);
},
});
}));
// for intercept 'sheet.command.set-row-is-auto-height' command.
sheetInterceptorService.interceptCommand({
this.disposeWithMe(sheetInterceptorService.interceptCommand({
getMutations: (command: { id: string; params: ISetWorksheetRowIsAutoHeightMutationParams }) => {
if (command.id !== SetWorksheetRowIsAutoHeightCommand.id) {
return {
Expand All @@ -116,10 +121,10 @@ export class AutoHeightController {

return this._getUndoRedoParamsOfAutoHeight(command.params.ranges);
},
});
}));

// for intercept set style command.
sheetInterceptorService.interceptCommand({
this.disposeWithMe(sheetInterceptorService.interceptCommand({
getMutations: (command: { id: string; params: ISetStyleCommandParams<number> }) => {
if (command.id !== SetStyleCommand.id) {
return {
Expand Down Expand Up @@ -150,6 +155,14 @@ export class AutoHeightController {

return this._getUndoRedoParamsOfAutoHeight(selections);
},
});
}));

this.disposeWithMe(this.autoHeightDirtyRanges$.subscribe((ranges) => {
this._getUndoRedoParamsOfAutoHeight(ranges);
}));
}

markRangeAutoHeightDirty(ranges: IRange[]) {
this._autoHeightDirtyRanges$.next(ranges);
}
}
1 change: 1 addition & 0 deletions packages/sheets-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ export type { IAutoFillLocation } from './services/auto-fill/type';
export type { IDiscreteRange } from './controllers/utils/range-tools';
export { virtualizeDiscreteRanges, rangeToDiscreteRange } from './controllers/utils/range-tools';
export { type IHoverCellPosition } from './services/hover-manager.service';
export { AutoHeightController } from './controllers/auto-height.controller';