Skip to content

Commit

Permalink
fix: formula show editor selection when using filter (#3621)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku authored Sep 29, 2024
1 parent 43a701f commit 1149cff
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import type { IWorkbookData } from '@univerjs/core';
import { AuthzIoLocalService, DisposableCollection, IAuthzIoService, ICommandService, Inject, Injector, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
import { ExclusiveRangeService, IExclusiveRangeService, RangeProtectionRuleModel, RefRangeService, SetWorksheetActiveOperation, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import type { ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter';
import { RemoveSheetsFilterMutation, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation, UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';
import { IMenuManagerService, IPlatformService, IShortcutService, MenuManagerService, PlatformService, ShortcutService } from '@univerjs/ui';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import type { IWorkbookData } from '@univerjs/core';
import type { ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter';
import { ClearSheetsFilterCriteriaCommand, ReCalcSheetsFilterCommand, SmartToggleSheetsFilterCommand } from '../../commands/commands/sheets-filter.command';
import { CloseFilterPanelOperation, OpenFilterPanelOperation } from '../../commands/operations/sheets-filter.operation';
import { ClearFilterCriteriaMenuItemFactory, ReCalcFilterMenuItemFactory, SmartToggleFilterMenuItemFactory } from '../sheets-filter.menu';
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-filter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import type { IMutationInfo, Nullable } from '@univerjs/core';
import type { ISetSheetsFilterCriteriaMutationParams } from './commands/mutations/sheets-filter.mutation';
import { SetSheetsFilterCriteriaMutation } from './commands/mutations/sheets-filter.mutation';
import type { ISetSheetsFilterCriteriaMutationParams } from './commands/mutations/sheets-filter.mutation';

interface ILine {
start: number;
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-formula/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@univerjs/icons": "^0.1.78",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
* limitations under the License.
*/

import type { ICellDataForSheetInterceptor, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IRowAutoHeightInfo, Nullable, Workbook, Worksheet } from '@univerjs/core';
import {
ColorKit, Disposable,
ICommandService,
ILogService,
Inject,
ObjectMatrix,
Rectangle,
ThemeService,
toDisposable,
} from '@univerjs/core';
Expand All @@ -31,17 +29,19 @@ import {
SetArrayFormulaDataMutation,
SetFormulaCalculationResultMutation,
} from '@univerjs/engine-formula';
import type { IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { ISetColHiddenMutationParams, ISetColVisibleMutationParams, ISetRowHiddenMutationParams, ISetRowVisibleMutationParams, ISetWorksheetColWidthMutationParams, ISetWorksheetRowAutoHeightMutationParams, ISetWorksheetRowHeightMutationParams } from '@univerjs/sheets';
import { SetColHiddenMutation, SetColVisibleMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation } from '@univerjs/sheets';
import { ReCalcSheetsFilterMutation, RemoveSheetsFilterMutation, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation } from '@univerjs/sheets-filter';
import {
IEditorBridgeService,
ISheetSelectionRenderService,
SELECTION_SHAPE_DEPTH,
SelectionShape,
SheetSkeletonManagerService,
} from '@univerjs/sheets-ui';
import type { ICellDataForSheetInterceptor, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IRowAutoHeightInfo, Nullable, Workbook, Worksheet } from '@univerjs/core';
import type { IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';
import type { ISetColHiddenMutationParams, ISetColVisibleMutationParams, ISetRowHiddenMutationParams, ISetRowVisibleMutationParams, ISetWorksheetColWidthMutationParams, ISetWorksheetRowAutoHeightMutationParams, ISetWorksheetRowHeightMutationParams } from '@univerjs/sheets';

const REFRESH_ARRAY_SHAPE_MUTATIONS = [
SetWorksheetRowHeightMutation.id,
Expand All @@ -50,6 +50,10 @@ const REFRESH_ARRAY_SHAPE_MUTATIONS = [
SetColVisibleMutation.id,
SetRowHiddenMutation.id,
SetRowVisibleMutation.id,
SetSheetsFilterRangeMutation.id,
SetSheetsFilterCriteriaMutation.id,
RemoveSheetsFilterMutation.id,
ReCalcSheetsFilterMutation.id,
];

export class FormulaEditorShowController extends Disposable implements IRenderModule {
Expand Down Expand Up @@ -273,7 +277,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo
this._previousShape = null;
}

private _refreshArrayFormulaRangeShape(unitId: string, range: IRange): void {
private _refreshArrayFormulaRangeShape(unitId: string, _range?: IRange): void {
if (this._previousShape) {
const { startRow, endRow, startColumn, endColumn } = this._previousShape.getRange();
const range = { startRow, endRow, startColumn, endColumn };
Expand All @@ -296,34 +300,10 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo
return false;
}

private _refreshArrayFormulaRangeShapeByRanges(unitId: string, subUnitId: string, ranges: IRange[]): void {
private _refreshArrayFormulaRangeShapeByRanges(unitId: string, subUnitId: string, ranges?: IRange[]): void {
if (!this._checkCurrentSheet(unitId, subUnitId)) return;

if (!this._previousShape) return;

const { startRow: shapeStartRow, endRow: shapeEndRow, startColumn: shapeStartColumn, endColumn: shapeEndColumn } = this._previousShape.getRange();

for (let i = 0; i < ranges.length; i++) {
const range = ranges[i];
const { startRow, endRow, startColumn, endColumn } = range;
if (Rectangle.intersects(
{
startRow, endRow, startColumn, endColumn,
},
{
startRow: shapeStartRow, endRow: shapeEndRow, startColumn: shapeStartColumn, endColumn: shapeEndColumn,
}
) || shapeStartRow >= endRow || startColumn >= endColumn) {
const shapeRange = {
startRow: shapeStartRow,
endRow: shapeEndRow,
startColumn: shapeStartColumn,
endColumn: shapeEndColumn,
};
this._refreshArrayFormulaRangeShape(unitId, shapeRange);
break;
}
}
this._refreshArrayFormulaRangeShape(unitId);
}

private _refreshArrayFormulaRangeShapeByRow(unitId: string, subUnitId: string, rowAutoHeightInfo: IRowAutoHeightInfo[]): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import type { IDisposable, Nullable, Workbook } from '@univerjs/core';
import { DisposableCollection, Inject, Injector, RANGE_TYPE, ThemeService, toDisposable } from '@univerjs/core';
import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, Viewport } from '@univerjs/engine-render';
import { ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';
import type { ISelectionStyle, ISelectionWithCoordAndStyle, ISelectionWithStyle, SheetsSelectionsService, WorkbookSelections } from '@univerjs/sheets';
import { convertSelectionDataToRange, getNormalSelectionStyle, IRefSelectionsService, SelectionMoveType } from '@univerjs/sheets';
import { attachSelectionWithCoord, BaseSelectionRenderService, checkInHeaderRanges, getAllSelection, getCoordByOffset, getSheetObject, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { IShortcutService } from '@univerjs/ui';
import type { IDisposable, Nullable, Workbook } from '@univerjs/core';
import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, Viewport } from '@univerjs/engine-render';
import type { ISelectionStyle, ISelectionWithCoordAndStyle, ISelectionWithStyle, SheetsSelectionsService, WorkbookSelections } from '@univerjs/sheets';

/**
* This service extends the existing `SelectionRenderService` to provide the rendering of prompt selections
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export { IMarkSelectionService } from './services/mark-selection/mark-selection.
export { SheetSelectionRenderService } from './services/selection/selection-render.service';
export { getAllSelection, getTopLeftSelection } from './services/selection/base-selection-render.service';
export { BaseSelectionRenderService, ISheetSelectionRenderService } from './services/selection/base-selection-render.service';
export { SelectionControl as SelectionShape } from './services/selection/selection-shape';
export { SelectionControl as SelectionShape } from './services/selection/selection-control';
export type { ISheetSkeletonManagerParam } from './services/sheet-skeleton-manager.service';
export { attachRangeWithCoord, SheetSkeletonManagerService } from './services/sheet-skeleton-manager.service';
export { UniverSheetsUIPlugin } from './sheets-ui-plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

import type { Workbook } from '@univerjs/core';
import { createIdentifier, Disposable, Inject, IUniverInstanceService, ThemeService, Tools, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { Workbook } from '@univerjs/core';
import type { ISelectionWithStyle } from '@univerjs/sheets';

// import { ISheetSelectionRenderService } from '../selection/base-selection-render.service';
import { SelectionControl } from '../selection/selection-shape';
import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import { ISheetSelectionRenderService } from '../selection/base-selection-render.service';
import { SELECTION_SHAPE_DEPTH } from '../selection/const';
// import { ISheetSelectionRenderService } from '../selection/base-selection-render.service';
import { SelectionControl } from '../selection/selection-control';
import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';

export interface IMarkSelectionService {
addShape(selection: ISelectionWithStyle, exits?: string[], zIndex?: number): string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* limitations under the License.
*/

import { createIdentifier, Disposable, InterceptorManager, makeCellToSelection, RANGE_TYPE } from '@univerjs/core';
import { ScrollTimer, ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';
import { getNormalSelectionStyle as getDefaultNormalSelectionStyle, transformCellDataToSelectionData } from '@univerjs/sheets';
import { BehaviorSubject, Subject } from 'rxjs';
import type {
IDisposable,
IFreeze,
Expand All @@ -35,14 +31,18 @@ import type { IMouseEvent, IPointerEvent, IRenderModule, Scene, SpreadsheetSkele
import type { ISelectionStyle, ISelectionWithCoordAndStyle, ISelectionWithStyle } from '@univerjs/sheets';
import type { IShortcutService } from '@univerjs/ui';
import type { Observable, Subscription } from 'rxjs';
import type { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import { createIdentifier, Disposable, InterceptorManager, makeCellToSelection, RANGE_TYPE } from '@univerjs/core';
import { ScrollTimer, ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';
import { getNormalSelectionStyle as getDefaultNormalSelectionStyle, transformCellDataToSelectionData } from '@univerjs/sheets';

import { BehaviorSubject, Subject } from 'rxjs';
import { SHEET_COMPONENT_SELECTION_LAYER_INDEX } from '../../common/keys';
import { RANGE_FILL_PERMISSION_CHECK, RANGE_MOVE_PERMISSION_CHECK } from './const';
import { SelectionControl } from './selection-control';
import { SelectionLayer } from './selection-layer';
import { SelectionControl } from './selection-shape';
import { SelectionShapeExtension } from './selection-shape-extension';
import { attachPrimaryWithCoord, attachSelectionWithCoord } from './util';
import type { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';

export interface IControlFillConfig {
oldRange: IRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import { RANGE_TYPE } from '@univerjs/core';
import { Rect, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';
import type { ThemeService } from '@univerjs/core';
import type { BaseObject, IRectProps, Scene } from '@univerjs/engine-render';
import type { ISelectionStyle } from '@univerjs/sheets';
import { RANGE_TYPE } from '@univerjs/core';
import { Rect, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';

import { SHEET_COMPONENT_SELECTION_LAYER_INDEX } from '../../common/keys';
import { SELECTION_MANAGER_KEY, SelectionControl } from './selection-shape';
import { SELECTION_MANAGER_KEY, SelectionControl } from './selection-control';

export class MobileSelectionControl extends SelectionControl {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import type { IFreeze, Injector, IRangeWithCoord, Nullable, ThemeService } from
import type { IMouseEvent, IPointerEvent, Scene, SpreadsheetSkeleton, Viewport } from '@univerjs/engine-render';

import type { Subscription } from 'rxjs';
import type { SelectionControl } from './selection-control';
import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import { ISheetSelectionRenderService } from './base-selection-render.service';
import { RANGE_FILL_PERMISSION_CHECK, RANGE_MOVE_PERMISSION_CHECK } from './const';
import type { SelectionControl } from './selection-shape';

const HELPER_SELECTION_TEMP_NAME = '__SpreadsheetHelperSelectionTempRect';

Expand Down
Loading

0 comments on commit 1149cff

Please sign in to comment.