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(sheet-ui): should not activate selection when clicking on header menu (#1117)

Wenzhao Hu30c78e45bc99
diff --git a/packages/design/src/components/popup/Popup.tsx b/packages/design/src/components/popup/Popup.tsx
index bf31669634..3887fdf34c 100644
--- a/packages/design/src/components/popup/Popup.tsx
+++ b/packages/design/src/components/popup/Popup.tsx
@@ -40,7 +40,7 @@ export function Popup(props: IPopupProps) {
const nodeRef = useRef(null);
- const [realoffset, setRealOffset] = useState<[number, number]>(offset);
+ const [realOffset, setRealOffset] = useState<[number, number]>(offset);
useEffect(() => {
if (!visible) {
@@ -66,7 +66,7 @@ export function Popup(props: IPopupProps) {
<CSSTransition
in={visible}
nodeRef={nodeRef}
- timeout={300}
+ timeout={500}
classNames={{
enter: styles.popupEnter,
enterActive: styles.popupEnterActive,
@@ -79,8 +79,11 @@ export function Popup(props: IPopupProps) {
ref={nodeRef}
className={styles.popup}
style={{
- left: realoffset[0],
- top: realoffset[1],
+ // Fix #1089. If the popup does not have this 2px offset, the pointerup event's target would
+ // become the popup itself not the canvas element, hence the selection gesture is not terminated.
+ // It should be considered as debt of the rendering engine.
+ left: realOffset[0] + 2,
+ top: realOffset[1] + 2,
}}
onContextMenu={preventDefault}
>
diff --git a/packages/sheets-ui/src/controllers/header-menu.controller.ts b/packages/sheets-ui/src/controllers/header-menu.controller.ts
index cb7a5863df..06aa3eafd9 100644
--- a/packages/sheets-ui/src/controllers/header-menu.controller.ts
+++ b/packages/sheets-ui/src/controllers/header-menu.controller.ts
@@ -15,10 +15,18 @@
*/
import type { Nullable, Observer } from '@univerjs/core';
-import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle, RANGE_TYPE } from '@univerjs/core';
+import {
+ Disposable,
+ ICommandService,
+ IUniverInstanceService,
+ LifecycleStages,
+ OnLifecycle,
+ RANGE_TYPE,
+} from '@univerjs/core';
import type { IMouseEvent, IPointerEvent } from '@univerjs/engine-render';
import { CURSOR_TYPE, IRenderManagerService, Rect } from '@univerjs/engine-render';
-import { SelectionManagerService } from '@univerjs/sheets';
+import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
+import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService, SetSelectionsOperation } from '@univerjs/sheets';
import { IContextMenuService } from '@univerjs/ui';
import { Inject } from '@wendellhu/redi';
@@ -58,6 +66,7 @@ export class HeaderMenuController extends Disposable {
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
+ @ICommandService private readonly _commandService: ICommandService,
@Inject(SelectionManagerService)
private readonly _selectionManagerService: SelectionManagerService
) {
@@ -257,7 +266,11 @@ export class HeaderMenuController extends Disposable {
});
if (!menuInSelections) {
- sheetObject.spreadsheetColumnHeader.onPointerDownObserver.notifyObservers(evt);
+ // Fix #1089
+ // Here we just change the selection here without any other operations.
+ // sheetObject.spreadsheetColumnHeader.onPointerDownObserver.notifyObservers(evt);
+ const selection = this._getSelectionOnColumn(currentColumn);
+ this._commandService.syncExecuteCommand(SetSelectionsOperation.id, selection);
}
evt.stopPropagation();
@@ -269,4 +282,37 @@ export class HeaderMenuController extends Disposable {
private _getSheetObject() {
return getSheetObject(this._currentUniverService, this._renderManagerService);
}
+
+ private _getSelectionOnColumn(column: number): ISetSelectionsOperationParams {
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+
+ return {
+ unitId: workbook.getUnitId(),
+ subUnitId: worksheet.getSheetId(),
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ selections: [
+ {
+ range: {
+ startRow: 0,
+ startColumn: column,
+ endRow: worksheet.getRowCount() - 1,
+ endColumn: column,
+ rangeType: RANGE_TYPE.COLUMN,
+ },
+ primary: {
+ startRow: 0,
+ startColumn: column,
+ endRow: 0,
+ endColumn: column,
+ actualRow: 0,
+ actualColumn: column,
+ isMerged: false,
+ isMergedMainCell: false,
+ },
+ style: null,
+ },
+ ],
+ };
+ }
}
diff --git a/packages/sheets-ui/src/controllers/selection.controller.ts b/packages/sheets-ui/src/controllers/selection.controller.ts
index e1344edc73..ae9d1aebc2 100644
--- a/packages/sheets-ui/src/controllers/selection.controller.ts
+++ b/packages/sheets-ui/src/controllers/selection.controller.ts
@@ -166,6 +166,7 @@ export class SelectionController extends Disposable {
this._getActiveViewport(evt),
ScrollTimerType.Y
);
+
if (evt.button !== 2) {
state.stopPropagation();
}
@@ -191,6 +192,7 @@ export class SelectionController extends Disposable {
this._getActiveViewport(evt),
ScrollTimerType.X
);
+
if (evt.button !== 2) {
state.stopPropagation();
}
diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.ts
index b804d62d3d..48974dd620 100644
--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts
+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts
@@ -261,6 +261,7 @@ export class SelectionRenderService implements ISelectionRenderService {
*/
addControlToCurrentByRangeData(data: ISelectionWithCoordAndStyle) {
const currentControls = this.getCurrentControls();
+
if (!currentControls) {
return;
}
@@ -1086,6 +1087,7 @@ export class SelectionRenderService implements ISelectionRenderService {
if (scene == null) {
return;
}
+
scene.onPointerMoveObserver.remove(this._moveObserver);
scene.onPointerUpObserver.remove(this._upObserver);
scene.enableEvent();