Skip to content

Commit

Permalink
fix: font left offset because of leftOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Oct 24, 2024
1 parent 18c1fe8 commit b090094
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,12 @@ export class SpreadsheetSkeleton extends Skeleton {
continue;
}
}
const measuredWidth = this.getMeasuredWidthByCell(cell);
let measuredWidth = this.getMeasuredWidthByCell(cell);

if (cell.fontRenderExtension) {
measuredWidth += ((cell.fontRenderExtension?.leftOffset || 0) + (cell.fontRenderExtension?.rightOffset || 0));
}

colWidth = Math.max(colWidth, measuredWidth);

// early return, if maxColWidth is larger than MAXIMUM_COL_WIDTH
Expand Down
36 changes: 1 addition & 35 deletions packages/sheets-ui/src/controllers/auto-width.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
import type { IColAutoWidthInfo, IObjectArrayPrimitiveType, IRange, Nullable, Workbook } from '@univerjs/core';
import type { RenderManagerService } from '@univerjs/engine-render';
import type {
ISetStyleCommandParams,
ISetWorksheetColIsAutoWidthMutationParams,
ISetWorksheetColWidthMutationParams,
} from '@univerjs/sheets';
import { Disposable, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import {
SetStyleCommand,
SetWorksheetColAutoWidthMutationFactory,
SetWorksheetColIsAutoWidthCommand,
SetWorksheetColWidthMutation,
SheetInterceptorService,
SheetsSelectionsService,
} from '@univerjs/sheets';
import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';

Expand All @@ -39,7 +36,6 @@ export class AutoWidthController extends Disposable {
constructor(
@IRenderManagerService private readonly _renderManagerService: RenderManagerService,
@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,
@Inject(SheetsSelectionsService) private readonly _selectionManagerService: SheetsSelectionsService,
@Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService
) {
super();
Expand Down Expand Up @@ -92,7 +88,7 @@ export class AutoWidthController extends Disposable {
}

private _initialize() {
const { _sheetInterceptorService: sheetInterceptorService, _selectionManagerService: selectionManagerService } =
const { _sheetInterceptorService: sheetInterceptorService } =
this;

// intercept 'sheet.command.set-col-is-auto-width' command.
Expand All @@ -108,35 +104,5 @@ export class AutoWidthController extends Disposable {
return this.getUndoRedoParamsOfColWidth(command.params.ranges);
},
}));

// for intercept set style command.
this.disposeWithMe(sheetInterceptorService.interceptCommand({
getMutations: (command: { id: string; params: ISetStyleCommandParams<number> }) => {
if (command.id !== SetStyleCommand.id) {
return {
redos: [],
undos: [],
};
}

if (!AFFECT_LAYOUT_STYLES.includes(command.params?.style.type)) {
return {
redos: [],
undos: [],
};
}

const selections = selectionManagerService.getCurrentSelections()?.map((s) => s.range);

if (!selections?.length) {
return {
redos: [],
undos: [],
};
}

return this.getUndoRedoParamsOfColWidth(selections);
},
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ export const SetWorksheetColWidthMutation: IMutation<ISetWorksheetColWidthMutati
return true;
},
};

Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ export class BasicWorksheetController extends Disposable implements IDisposable
SetWorksheetRowIsAutoHeightMutation,
SetWorksheetColWidthMutation,
SetWorksheetColIsAutoWidthCommand,
// SetWorksheetColIsAutoWidthMutation,

SetSelectionsOperation,
ScrollToCellOperation,
Expand Down

0 comments on commit b090094

Please sign in to comment.