Skip to content

Commit

Permalink
chore: better code
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Oct 23, 2024
1 parent 085d8cc commit 955e0e5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 57 deletions.
1 change: 0 additions & 1 deletion packages/core/src/sheets/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ export interface IColumnData {

export interface IColAutoWidthInfo {
col: number;
// autoWidth?: number;
width?: number;
}

Expand Down
20 changes: 8 additions & 12 deletions packages/engine-render/src/components/sheets/sheet-skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,6 @@ export class SpreadsheetSkeleton extends Skeleton {
}

const results: IColAutoWidthInfo[] = [];
const { rowData } = this._worksheetData;
const rowObjectArray = rowData;
const calculatedCols = new Set<number>();

for (const range of ranges) {
Expand All @@ -718,11 +716,6 @@ export class SpreadsheetSkeleton extends Skeleton {
continue;
}

// The row sets ia to false, and there is no need to calculate the automatic row height for the row.
if (rowObjectArray[colIndex]?.ia === BooleanNumber.FALSE) {
continue;
}

const hasUnMergedCell = this._hasUnMergedCellInColumn(colIndex, startRow, endRow);

if (hasUnMergedCell) {
Expand All @@ -740,7 +733,8 @@ export class SpreadsheetSkeleton extends Skeleton {
}

/**
* Iterate all rows and return column width of the specified column(by column index)
* Iterate rows in visible area(and rows around it) and return column width of the specified column(by column index)
*
* @param colIndex
* @returns {number} width
*/
Expand All @@ -755,9 +749,6 @@ export class SpreadsheetSkeleton extends Skeleton {
return maxColWidth;
}

// for performance: calc first and last row,
// then we can skip rows that are not in the range.

const getMeasuredWidthByCell = (cell: ICellDataForSheetInterceptor) => {
let measuredWidth = 0;
if (cell?.interceptorAutoWidth) {
Expand Down Expand Up @@ -817,6 +808,11 @@ export class SpreadsheetSkeleton extends Skeleton {
return measuredWidth;
};

// for cell with only v, auto size for content width in visible range and ± 10000 rows around.
// for cell with p, auto width for cotent in visible range and ± 1000 rows, 1/10 of situation above.
// first row and last row should be considerated.
// skip hidden row, merged cell
// also handle mutiple viewport situation (freeze row & freeze row&col)
const visibleRangeViewMain = this.visibleRangeByViewportKey(SHEET_VIEWPORT_KEY.VIEW_MAIN);
if (!visibleRangeViewMain) return maxColWidth;

Expand Down Expand Up @@ -852,7 +848,7 @@ export class SpreadsheetSkeleton extends Skeleton {
maxColWidth = Math.max(maxColWidth, measuredWidth);
}

// check width of first row and last row
// check width of first row and last row, and rows in viewMainTop(viewMainTopLeft are included)
const otherRowIndex: Set<number> = new Set();
otherRowIndex.add(0);
otherRowIndex.add(rowCount - 1);
Expand Down
1 change: 0 additions & 1 deletion packages/sheets/src/basics/const/command-listener-const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { SetColHiddenMutation, SetColVisibleMutation } from '../../commands/muta
import { SetRangeValuesMutation } from '../../commands/mutations/set-range-values.mutation';
import { SetRowHiddenMutation, SetRowVisibleMutation } from '../../commands/mutations/set-row-visible.mutation';
import { SetWorksheetColAutoWidthMutation, SetWorksheetColWidthMutation } from '../../commands/mutations/set-worksheet-col-width.mutation';
import { SetWorksheetColWidthMutation } from '../../commands/mutations/set-worksheet-col-width.mutation';
import { SetWorksheetDefaultStyleMutation } from '../../commands/mutations/set-worksheet-default-style.mutations';
import { SetWorksheetRowColumnStyleMutation } from '../../commands/mutations/set-worksheet-row-column-style.mutation';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,11 @@ export const SetWorksheetColIsAutoWidthCommand: ICommand = {
unitId,
subUnitId,
ranges,
// autoWidthInfo: BooleanNumber.TRUE, // Hard code first, maybe it will change by the menu item in the future.
};

// const undoMutationParams: ISetWorksheetColIsAutoWidthMutationParams =
SetWorksheetColIsAutoWidthMutationFactory(redoMutationParams, worksheet);

// const setIsAutoWidthResult = commandService.syncExecuteCommand(
// SetWorksheetColIsAutoWidthMutation.id,
// redoMutationParams
// );

// undos redos comes from auto-width.controller
// for intercept 'sheet.command.set-col-is-auto-width' command.
const { undos, redos } = accessor.get(SheetInterceptorService).onCommandExecute({
Expand All @@ -256,12 +250,8 @@ export const SetWorksheetColIsAutoWidthCommand: ICommand = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: [
// { id: SetWorksheetColIsAutoWidthMutation.id, params: undoMutationParams },
...undos],
redoMutations: [
// { id: SetWorksheetColIsAutoWidthMutation.id, params: redoMutationParams },
...redos],
undoMutations: [...undos],
redoMutations: [...redos],
});

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface ISetWorksheetColIsAutoWidthMutationParams {
unitId: string;
subUnitId: string;
ranges: IRange[];
// autoWidthInfo: BooleanNumber | IObjectArrayPrimitiveType<Nullable<BooleanNumber>>;
}

export interface ISetWorksheetColAutoWidthMutationParams {
Expand Down Expand Up @@ -147,35 +146,6 @@ export const SetWorksheetColWidthMutation: IMutation<ISetWorksheetColWidthMutati
},
};

// /**
// * set is auto width)
// */
// export const SetWorksheetColIsAutoWidthMutation: IMutation<ISetWorksheetColIsAutoWidthMutationParams> = {
// id: 'sheet.mutation.set-worksheet-col-is-auto-width',
// type: CommandType.MUTATION,
// handler: (accessor, params) => {
// const { ranges, autoWidthInfo } = params;
// const univerInstanceService = accessor.get(IUniverInstanceService);
// const target = getSheetCommandTarget(univerInstanceService, params);
// if (!target) return false;

// const manager = target.worksheet.getColumnManager();
// for (const { startColumn, endColumn } of ranges) {
// for (let index = startColumn; index <= endColumn; index++) {
// const col = manager.getColumnOrCreate(index);

// if (typeof autoWidthInfo === 'number') {
// col.ia = autoWidthInfo;
// } else {
// col.ia = autoWidthInfo[index] ?? undefined;
// }
// }
// }

// return true;
// },
// };

/**
* Apply auto width value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ import { SetRowHiddenMutation, SetRowVisibleMutation } from '../commands/mutatio
import { SetTabColorMutation } from '../commands/mutations/set-tab-color.mutation';
import { SetWorkbookNameMutation } from '../commands/mutations/set-workbook-name.mutation';
import { SetWorksheetColAutoWidthMutation, SetWorksheetColWidthMutation } from '../commands/mutations/set-worksheet-col-width.mutation';
import { SetWorksheetColWidthMutation } from '../commands/mutations/set-worksheet-col-width.mutation';
import { SetWorksheetDefaultStyleMutation } from '../commands/mutations/set-worksheet-default-style.mutations';
import { SetWorksheetHideMutation } from '../commands/mutations/set-worksheet-hide.mutation';
import { SetWorksheetNameMutation } from '../commands/mutations/set-worksheet-name.mutation';
Expand Down

0 comments on commit 955e0e5

Please sign in to comment.