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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: fix context menu cannot trigger selection change (#4734)
Wenzhao Hu40956fdb453b
diff --git a/packages/sheets-formula-ui/src/services/render-services/ref-selections.render-service.ts b/packages/sheets-formula-ui/src/services/render-services/ref-selections.render-service.tsindex 90a7f0dad3..f61c3cc7c8 100644--- a/packages/sheets-formula-ui/src/services/render-services/ref-selections.render-service.ts+++ b/packages/sheets-formula-ui/src/services/render-services/ref-selections.render-service.ts@@ -17,7 +17,7 @@import type { IDisposable, IRangeWithCoord, Nullable, Workbook } from '@univerjs/core';import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, Scene, SpreadsheetSkeleton, Viewport } from '@univerjs/engine-render';import type { ISelectionStyle, ISelectionWithCoord, ISelectionWithStyle, SheetsSelectionsService, WorkbookSelectionModel } from '@univerjs/sheets';-import { DisposableCollection, IContextService, Inject, Injector, RANGE_TYPE, ThemeService, toDisposable } from '@univerjs/core';+import { DisposableCollection, IContextService, Inject, Injector, RANGE_TYPE, Rectangle, ThemeService, toDisposable } from '@univerjs/core';import { ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';import { convertSelectionDataToRange, IRefSelectionsService, SelectionMoveType } from '@univerjs/sheets';import { attachSelectionWithCoord, BaseSelectionRenderService, checkInHeaderRanges, genNormalSelectionStyle, getAllSelection, getCoordByOffset, getSheetObject, SelectionControl, SheetSkeletonManagerService } from '@univerjs/sheets-ui';@@ -336,8 +336,9 @@ export class RefSelectionsRenderService extends BaseSelectionRenderService implelet activeSelectionControl: Nullable<SelectionControl> = this.getActiveSelectionControl();const curControls = this.getSelectionControls();for (const control of curControls) {- // right click should not create a new selection, it pops up the context menu.- if (evt.button === 2 && control.model.isInclude(cursorCellRangeWithRangeType)) {+ // If right click on a selection, we should not create a new selection control.+ // Instead, the context menu will popup.+ if (evt.button === 2 && Rectangle.contains(control.model, cursorCellRangeWithRangeType)) {activeSelectionControl = control;return;}diff --git a/packages/sheets-ui/src/controllers/render-controllers/header-menu.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/header-menu.render-controller.tsindex 39cd16cf73..78ab9175c2 100644--- a/packages/sheets-ui/src/controllers/render-controllers/header-menu.render-controller.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/header-menu.render-controller.ts@@ -14,6 +14,9 @@* limitations under the License.*/+import type { Nullable, Workbook } from '@univerjs/core';+import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, SpreadsheetColumnHeader, SpreadsheetHeader } from '@univerjs/engine-render';+import type { ISetSelectionsOperationParams } from '@univerjs/sheets';import {Disposable,ICommandService,@@ -24,9 +27,6 @@ import { CURSOR_TYPE, Rect } from '@univerjs/engine-render';import { SetSelectionsOperation, SheetsSelectionsService } from '@univerjs/sheets';import { ContextMenuPosition, IContextMenuService } from '@univerjs/ui';import { Subscription } from 'rxjs';-import type { Nullable, Workbook } from '@univerjs/core';-import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, SpreadsheetColumnHeader, SpreadsheetHeader } from '@univerjs/engine-render';-import type { ISetSelectionsOperationParams } from '@univerjs/sheets';import { SHEET_COMPONENT_HEADER_LAYER_INDEX, SHEET_VIEW_KEY } from '../../common/keys';import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service';diff --git a/packages/sheets-ui/src/controllers/render-controllers/header-unhide.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/header-unhide.render-controller.tsindex c310c5bcc3..b307f3e702 100644--- a/packages/sheets-ui/src/controllers/render-controllers/header-unhide.render-controller.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/header-unhide.render-controller.ts@@ -15,28 +15,16 @@*/import type { Workbook, Worksheet } from '@univerjs/core';+import type { IRenderContext } from '@univerjs/engine-render';+import type { ISetSpecificColsVisibleCommandParams, ISetSpecificRowsVisibleCommandParams } from '@univerjs/sheets';import {ICommandService,Inject,RxDisposable,} from '@univerjs/core';-import type { IRenderContext } from '@univerjs/engine-render';-import type { ISetSpecificColsVisibleCommandParams, ISetSpecificRowsVisibleCommandParams } from '@univerjs/sheets';import {- InsertColMutation,- InsertRowMutation,- MoveColsMutation,- MoveRowsMutation,- RemoveColMutation,- RemoveRowMutation,- SetColHiddenMutation,- SetColVisibleMutation,- SetRowHiddenMutation,- SetRowVisibleMutation,SetSpecificColsVisibleCommand,SetSpecificRowsVisibleCommand,- SetWorksheetColWidthMutation,- SetWorksheetRowIsAutoHeightMutation,} from '@univerjs/sheets';import { takeUntil } from 'rxjs';@@ -47,21 +35,6 @@ import { getCoordByCell, getSheetObject } from '../utils/component-tools';const HEADER_UNHIDE_CONTROLLER_SHAPE = '__SpreadsheetHeaderUnhideSHAPEControllerShape__';-const RENDER_COMMANDS: string[] = [- InsertColMutation.id,- InsertRowMutation.id,- RemoveColMutation.id,- RemoveRowMutation.id,- MoveColsMutation.id,- MoveRowsMutation.id,- SetWorksheetColWidthMutation.id,- SetWorksheetRowIsAutoHeightMutation.id,- SetRowHiddenMutation.id,- SetRowVisibleMutation.id,- SetColHiddenMutation.id,- SetColVisibleMutation.id,-];-/*** This controller controls rendering of the buttons to unhide hidden rows and columns.*/diff --git a/packages/sheets-ui/src/services/selection/selection-render-model.ts b/packages/sheets-ui/src/services/selection/selection-render-model.tsindex 98115c1d09..cf49a9e9d6 100644--- a/packages/sheets-ui/src/services/selection/selection-render-model.ts+++ b/packages/sheets-ui/src/services/selection/selection-render-model.ts@@ -76,26 +76,6 @@ export class SelectionRenderModel implements IRangeWithCoord {return false;}- /**- * @deprecated, Duplicate with `Rectangle`- */- isInclude(rangeWithCoord: IRangeWithCoord) {- const { startColumn, startRow, endColumn, endRow } = this;- const {- startColumn: newStartColumn,- startRow: newStartRow,- endColumn: newEndColumn,- endRow: newEndRow,- } = rangeWithCoord;-- if (- !(newEndColumn < startColumn || newStartColumn > endColumn || newStartRow > endRow || newEndRow < startRow)- ) {- return true;- }- return false;- }-highlightToSelection(): Nullable<IRangeWithCoord> {if (!this._primary) return;return convertCellToRange(this._primary);diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.tsindex 3aa1079a11..73b9ec73ff 100644--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts@@ -19,7 +19,7 @@ import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, Viewporimport type { ISelectionWithCoord, ISelectionWithStyle, ISetSelectionsOperationParams, WorkbookSelectionModel } from '@univerjs/sheets';import type { ISheetObjectParam } from '../../controllers/utils/component-tools';import type { SelectionControl } from './selection-control';-import { ICommandService, IContextService, ILogService, Inject, Injector, RANGE_TYPE, ThemeService, toDisposable } from '@univerjs/core';+import { ICommandService, IContextService, ILogService, Inject, Injector, RANGE_TYPE, Rectangle, ThemeService, toDisposable } from '@univerjs/core';import { ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';import { convertSelectionDataToRange, REF_SELECTIONS_ENABLED, SelectionMoveType, SELECTIONS_ENABLED, SetSelectionsOperation, SheetsSelectionsService } from '@univerjs/sheets';import { IShortcutService } from '@univerjs/ui';@@ -110,6 +110,9 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService implconst skeleton = this._sheetSkeletonManagerService.getCurrentParam()!.skeleton;const { column } = getCoordByOffset(evt.offsetX, evt.offsetY, scene, skeleton);++ // We should take if this is col selection into consideration.+const matchSelectionData = isThisColSelected(this._workbookSelections.getCurrentSelections(), column);if (matchSelectionData) return;@@ -386,16 +389,12 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService implconst cursorRangeWidthCoord: IRangeWithCoord = { ...selectionCellWithCoord.rangeWithCoord, rangeType };const curControls = this.getSelectionControls();for (const control of curControls) {- // right click- if (evt.button === 2 && control.model.isInclude(cursorRangeWidthCoord)) {+ // If right click on a selection, we should not create a new selection control.+ // Instead, the context menu will popup.+ if (evt.button === 2 && Rectangle.contains(control.model, cursorRangeWidthCoord)) {activeSelectionControl = control;return;}- // Click to an existing selection, then what?- // if (control.model.isEqual(cursorCellRangeWithRangeType)) {- // activeSelectionControl = control;- // break;- // }}this._checkClearPreviousControls(evt);