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: use a temp solution to fix context menu won't show

Wenzhao Hua235eda94fe1
diff --git a/packages/base-ui/src/services/contextmenu/contextmenu.service.ts b/packages/base-ui/src/services/contextmenu/contextmenu.service.ts
index 299a4e313f..9dc9a8111c 100644
--- a/packages/base-ui/src/services/contextmenu/contextmenu.service.ts
+++ b/packages/base-ui/src/services/contextmenu/contextmenu.service.ts
@@ -25,18 +25,24 @@ export class DesktopContextMenuService extends Disposable implements IContextMen
}
this._currentHandler = handler;
- const pointerDownOnMain = this._renderingEngine.getScene('mainScene')?.onPointerDownObserver;
- const observer = pointerDownOnMain?.add((event: IPointerEvent | IMouseEvent) => {
- // right click
- if (event.button === 2) {
- event.preventDefault();
- this._currentHandler?.handleContextMenu(event);
- }
- });
+
+ // FIXME@wzhudev: shouldn't set timeout here, because we should not get pointer down event on mainScene but
+ // rendering engine itself
+ setTimeout(() => {
+ const mainScene = this._renderingEngine.getScene('mainScene');
+ const pointerDownOnMain = mainScene!.onPointerDownObserver;
+ const observer = pointerDownOnMain?.add((event: IPointerEvent | IMouseEvent) => {
+ // right click
+ if (event.button === 2) {
+ event.preventDefault();
+ this._currentHandler?.handleContextMenu(event);
+ }
+ });
+ }, 200);
return toDisposable(() => {
this._currentHandler = null;
- pointerDownOnMain?.remove(observer);
+ // pointerDownOnMain?.remove(observer);
});
}
}
diff --git a/packages/base-ui/src/views/components/contextmenu/contextmenu.tsx b/packages/base-ui/src/views/components/contextmenu/contextmenu.tsx
index 7a42e96725..7028765bba 100644
--- a/packages/base-ui/src/views/components/contextmenu/contextmenu.tsx
+++ b/packages/base-ui/src/views/components/contextmenu/contextmenu.tsx
@@ -48,7 +48,6 @@ export class ContextMenu extends Component<IContextMenuProps, IContextMenuState>
override componentDidMount() {
document.addEventListener('click', this.handleClick);
- // TODO: dispose
this._disposables.add(
this.contextMenuService.registerContextMenuHandler({
handleContextMenu: this.handleContextMenu,