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: filter rollback in another worksheet #3896

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"Quan",
"rbush",
"redi",
"rowheader",
"shrinkability",
"Sider",
"strechability",
Expand Down
17 changes: 9 additions & 8 deletions packages/core/src/shared/array-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ export function searchInOrderedArray(arr: number[], target: number) {
/**
* Return the index of the first value in an ascending array that is greater than the target value. If there is no value greater than the target, return last index.
*
*
* binarySearchArray([0,1,2,3,4, 4, 4,5, 5, 5], 1) return 2
* binarySearchArray([0,1,2,3,4, 4, 4, 5, 5, 5], 5) return last index, because max value 5 is not greater than target 5
* binarySearchArray([0,1,2,3,4, 4, 4, 5, 5, 5], 8) return last index, because max value 5 is not greater than target 8.
* @param arr
* @param pos
*/
// binarySearchArray([0, 1, 2, 3, 4, 4, 4, 5, 5, 5], 1) return 2
// binarySearchArray([0, 1, 2, 3, 4, 4, 4, 5, 5, 5], 5) return last index, because max value 5 is not greater than target 5
// binarySearchArray([0, 1, 2, 3, 4, 4, 4, 5, 5, 5], 8) return last index, because max value 5 is not greater than target 8.
export function binarySearchArray(arr: number[], pos: number) {
let low: number = 0;
let high = arr.length - 1;
Expand Down Expand Up @@ -96,12 +95,13 @@ export function binarySearchArray(arr: number[], pos: number) {
*
* Alternatively, you can consider inserting a number to ensure the array remains sorted, and return the position for insertion.
*
* binarySearchArray([0,1,2,3,4, 4, 4,5, 5, 5], 1) return 2
* binarySearchArray([0,1,2,3,4, 4, 4, 5, 5, 5], 5) return last index, because max value 5 is not greater than target 5
* binarySearchArray([0,1,2,3,4, 4, 4, 5, 5, 5], 8) return last index, because max value 5 is not greater than target 8.
* @param arr
* @param target
*/

// binarySearchArray ([0, 1, 2, 3, 4, 4, 4, 5, 5, 5], 1) return 2
// binarySearchArray ([0, 1, 2, 3, 4, 4, 4, 5, 5, 5], 5) return last index, because max value 5 is not greater than target 5
// binarySearchArray ([0, 1, 2, 3, 4, 4, 4, 5, 5, 5], 8) return last index, because max value 5 is not greater than target 8.
export function binSearchFirstGreaterThanTarget(arr: number[], target: number) {
let left = 0;
let right = arr.length;
Expand All @@ -124,7 +124,8 @@ export function binSearchFirstGreaterThanTarget(arr: number[], target: number) {

/**
* Find value in the data that is just greater than the target; if there are equal values greater than the target, select the last one.
* Translation: If firstMatch is true, then return the index of the first number greater than the target.
* If firstMatch is true, then return the index of the first number greater than the target.
* see #univer/pull/3903
*
* @param arr ascending array
* @param target value wants to find
Expand Down
13 changes: 6 additions & 7 deletions packages/engine-render/src/components/sheets/sheet-skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,13 @@ export class SpreadsheetSkeleton extends Skeleton {
columnHeader,
showGridlines,
} = this._worksheetData;

const { rowTotalHeight, rowHeightAccumulation } = this._generateRowMatrixCache(
rowCount,
rowData,
defaultRowHeight
);

const { columnTotalWidth, columnWidthAccumulation } = this._generateColumnMatrixCache(
columnCount,
columnData,
Expand Down Expand Up @@ -1000,12 +1002,9 @@ export class SpreadsheetSkeleton extends Skeleton {
columnCount: number
): IColumnRange {
const contentWidth = contentSize?.width ?? 0;

let startColumn = column;
let endColumn = column;

// console.log('documentSkeleton', cell?.v, column, endColumn, row, column, columnCount, contentWidth);

if (horizontalAlign === HorizontalAlign.CENTER) {
startColumn = this._getOverflowBound(row, column, 0, contentWidth / 2, horizontalAlign);
endColumn = this._getOverflowBound(row, column, columnCount - 1, contentWidth / 2, horizontalAlign);
Expand Down Expand Up @@ -1836,10 +1835,10 @@ export class SpreadsheetSkeleton extends Skeleton {
this._overflowCache.reset();
}

private _makeDocumentSkeletonDirty(row: number, col: number): void {
if (this._stylesCache.fontMatrix == null) return;
this._stylesCache.fontMatrix.getValue(row, col)?.documentSkeleton.makeDirty(true); ;
}
// private _makeDocumentSkeletonDirty(row: number, col: number): void {
// if (this._stylesCache.fontMatrix == null) return;
// this._stylesCache.fontMatrix.getValue(row, col)?.documentSkeleton.makeDirty(true); ;
// }

_setBorderStylesCache(row: number, col: number, style: Nullable<IStyleData>, options: {
mergeRange?: IRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class Spreadsheet extends SheetComponent {
// The 'leftOrigin' is the offset of the viewport relative to the sheet corner, which is the position of cell(0, 0), and it does not consider scaling.
// - (leftOrigin - bufferEdgeX) ----> - leftOrigin + bufferEdgeX
cacheCtx.translateWithPrecision(m.e / m.a - leftOrigin + bufferEdgeX, m.f / m.d - topOrigin + bufferEdgeY);
// when extension drawing, sheet content corrdinate was used by sheet extension, not viewport corrdinate, that means ext does not take rowheader into consideration
// when extension drawing, sheet content coordinate was used by sheet extension, not viewport coordinate, that means ext does not take rowheader into consideration
this.draw(cacheCtx, viewportInfo);
cacheCtx.restore();
}
Expand Down
1 change: 0 additions & 1 deletion packages/sheets-filter/src/models/filter-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,3 @@ function extractFilterValueFromCell(cell: ICellData): string | number {

return '';
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
Viewport,
} from '@univerjs/engine-render';

import { COMMAND_LISTENER_SKELETON_CHANGE, COMMAND_LISTENER_VALUE_CHANGE, MoveRangeMutation, SetRangeValuesMutation, SetWorksheetActiveOperation } from '@univerjs/sheets';
import { COMMAND_LISTENER_SKELETON_CHANGE, COMMAND_LISTENER_VALUE_CHANGE, MoveRangeMutation, SetRangeValuesMutation } from '@univerjs/sheets';
import { ITelemetryService } from '@univerjs/telemetry';
import { Subject, withLatestFrom } from 'rxjs';
import {
Expand Down Expand Up @@ -367,29 +367,29 @@ export class SheetRenderController extends RxDisposable implements IRenderModule
const { id: commandId } = command;

if (COMMAND_LISTENER_SKELETON_CHANGE.includes(commandId) || this._sheetRenderService.checkMutationShouldTriggerRerender(commandId)) {
const params = command.params;
const { unitId, subUnitId } = params as ISetWorksheetMutationParams;
// const worksheet = subUnitId ? workbook?.getSheetBySheetId(subUnitId) : workbook.getActiveSheet();

const worksheet = workbook.getActiveSheet();
if (!worksheet) return;

const workbookId = this._context.unitId;
const worksheetId = worksheet.getSheetId();
const params = command.params;
const { unitId, subUnitId } = params as ISetWorksheetMutationParams;

if (unitId !== workbookId || subUnitId !== worksheetId) {
return;
}

if (commandId !== SetWorksheetActiveOperation.id) {
this._sheetSkeletonManagerService.makeDirty({
sheetId: worksheetId,
commandId,
}, true);
}
// DO NOT judge if SetWorksheetActiveOperation is executed.
// issue #univer-pro/issues/2310
// if (commandId !== SetWorksheetActiveOperation.id) {
// }
this._sheetSkeletonManagerService.makeDirty({
sheetId: worksheetId,
commandId,
}, true);

// Change the skeleton to render when the sheet is changed.
// Should also check the init sheet.
// setCurrent ---> currentSkeletonBefore$ ---> zoom.controller.subscribe ---> scene._setTransForm ---> viewports markDirty
// setCurrent ---> currentSkeleton$ ---> scroll.controller.subscribe ---> scene?.transformByState ---> scene._setTransFor
this._sheetSkeletonManagerService.setCurrent({
sheetId: worksheetId,
commandId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export class SheetSkeletonManagerService extends Disposable implements IRenderMo
param.skeleton.calculate();
}

/**
* Make param dirty, if param is dirty, then the skeleton will be makeDirty in _reCalculate()
* @param searchParm
* @param state
*/
makeDirty(searchParm: ISheetSkeletonManagerSearch, state: boolean = true) {
const param = this._getSkeleton(searchParm);
if (param == null) {
Expand Down
Loading