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

This commit is contained in:
WEI ZHANG
2025-12-02 15:47:39 +08:00
committed by GitHub
parent 3c5d384034
commit 2feee7e401
2 changed files with 19 additions and 14 deletions
@@ -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
@@ -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);
}