Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-ui): popup not update corretly on selection changes (#6236)

WEI ZHANG2feee7e4014e
diff --git a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
index 8918dc4047..cdb61889bb 100644
--- a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
+++ b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
@@ -17,14 +17,14 @@
import type { IDisposable, IDrawingSearch, IPosition, IRange, ITransformState, Nullable, Serializable, Workbook, Worksheet } from '@univerjs/core';
import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
import type { BaseObject, IBoundRectNoAngle, IRectProps, IRender, Scene, SpreadsheetSkeleton } from '@univerjs/engine-render';
-import type { ISetFrozenMutationParams, ISetWorksheetRowAutoHeightMutationParams } from '@univerjs/sheets';
+import type { ISetFrozenMutationParams, ISetSelectionsOperationParams, ISetWorksheetRowAutoHeightMutationParams } from '@univerjs/sheets';
import type { IFloatDomData, ISheetDrawingPosition, ISheetFloatDom } from '@univerjs/sheets-drawing';
import type { IFloatDom, IFloatDomLayout } from '@univerjs/ui';
import type { IInsertDrawingCommandParams } from '../commands/commands/interfaces';
import { Disposable, DisposableCollection, DrawingTypeEnum, fromEventSubject, generateRandomId, ICommandService, Inject, IUniverInstanceService, LifecycleService, LifecycleStages, Tools, UniverInstanceType } from '@univerjs/core';
import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import { DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, ObjectType, Rect, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';
-import { COMMAND_LISTENER_SKELETON_CHANGE, getSheetCommandTarget, SetFrozenMutation, SetWorksheetRowAutoHeightMutation } from '@univerjs/sheets';
+import { COMMAND_LISTENER_SKELETON_CHANGE, getSheetCommandTarget, SetFrozenMutation, SetSelectionsOperation, SetWorksheetRowAutoHeightMutation } from '@univerjs/sheets';
import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';
import { ISheetSelectionRenderService, SetScrollOperation, SetZoomRatioOperation, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { CanvasFloatDomService } from '@univerjs/ui';
@@ -560,6 +560,9 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
} else if (commandInfo.id === SetFrozenMutation.id) {
const { unitId, subUnitId } = commandInfo.params as ISetFrozenMutationParams;
updateSheet(unitId, subUnitId);
+ } else if (commandInfo.id === SetSelectionsOperation.id) {
+ const { unitId, subUnitId } = commandInfo.params as ISetSelectionsOperationParams;
+ updateSheet(unitId, subUnitId);
}
}));
//# endregion
diff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
index ef574073eb..082fa3ed7d 100644
--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
@@ -20,7 +20,7 @@ import type { ISetWorksheetRowAutoHeightMutationParams, ISheetLocationBase } fro
import type { IPopup } from '@univerjs/ui';
import { Disposable, DisposableCollection, fromEventSubject, ICommandService, Inject, IUniverInstanceService, toDisposable, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { COMMAND_LISTENER_SKELETON_CHANGE, IRefSelectionsService, RefRangeService, SetFrozenMutation, SetWorksheetRowAutoHeightMutation, SheetsSelectionsService } from '@univerjs/sheets';
+import { COMMAND_LISTENER_SKELETON_CHANGE, IRefSelectionsService, RefRangeService, SetFrozenMutation, SetSelectionsOperation, SetWorksheetRowAutoHeightMutation, SheetsSelectionsService } from '@univerjs/sheets';
import { ICanvasPopupService } from '@univerjs/ui';
import { BehaviorSubject, map, throttleTime } from 'rxjs';
import { SetScrollOperation } from '../commands/operations/scroll.operation';
@@ -228,7 +228,7 @@ export class SheetCanvasPopManagerService extends Disposable {
const disposable = new DisposableCollection();
disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
- if (commandInfo.id === SetScrollOperation.id || commandInfo.id === SetZoomRatioOperation.id) {
+ if (shouldUpdatePosition(commandInfo.id)) {
position$.next(calc());
}
}));
@@ -616,11 +616,7 @@ export class SheetCanvasPopManagerService extends Disposable {
}
}
- if (
- COMMAND_LISTENER_SKELETON_CHANGE.indexOf(commandInfo.id) > -1 ||
- commandInfo.id === SetScrollOperation.id ||
- commandInfo.id === SetZoomRatioOperation.id
- ) {
+ if (shouldUpdatePosition(commandInfo.id)) {
updatePosition();
}
}));
@@ -733,11 +729,7 @@ export class SheetCanvasPopManagerService extends Disposable {
}
}
- if (
- COMMAND_LISTENER_SKELETON_CHANGE.indexOf(commandInfo.id) > -1 ||
- commandInfo.id === SetScrollOperation.id ||
- commandInfo.id === SetZoomRatioOperation.id
- ) {
+ if (shouldUpdatePosition(commandInfo.id)) {
updatePosition();
}
}));
@@ -782,3 +774,13 @@ export class SheetCanvasPopManagerService extends Disposable {
function pxToNum(width: string): number {
return Number.parseInt(width.replace('px', ''));
}
+
+const POSITION_UPDATE_COMMANDS = new Set([
+ SetScrollOperation.id,
+ SetZoomRatioOperation.id,
+ SetSelectionsOperation.id,
+]);
+
+function shouldUpdatePosition(commandId: string): boolean {
+ return POSITION_UPDATE_COMMANDS.has(commandId) || COMMAND_LISTENER_SKELETON_CHANGE.includes(commandId);
+}