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: disable image when select table (#2962)

Ran Luo770385b0269b
diff --git a/packages/docs-drawing-ui/src/views/menu/image.menu.ts b/packages/docs-drawing-ui/src/views/menu/image.menu.ts
index 147f792330..d914963d45 100644
--- a/packages/docs-drawing-ui/src/views/menu/image.menu.ts
+++ b/packages/docs-drawing-ui/src/views/menu/image.menu.ts
@@ -19,7 +19,7 @@ import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import type { IAccessor } from '@univerjs/core';
import { TextSelectionManagerService } from '@univerjs/docs';
-import { combineLatest, Observable } from 'rxjs';
+import { Observable } from 'rxjs';
import { COMPONENT_DOC_UPLOAD_FILE_MENU } from '../upload-component/component-name';
export const ImageUploadIcon = 'addition-and-subtraction-single';
@@ -49,6 +49,9 @@ const getDisableWhenSelectionInTableObservable = (accessor: IAccessor) => {
return;
}
}
+ } else {
+ subscriber.next(true);
+ return;
}
subscriber.next(false);
@@ -66,9 +69,8 @@ export function ImageMenuFactory(accessor: IAccessor): IMenuItem {
group: MenuGroup.TOOLBAR_LAYOUT,
icon: ImageUploadIcon,
tooltip: 'docImage.title',
- hidden$: combineLatest(getDisableWhenSelectionInTableObservable(accessor), getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), (one, two) => {
- return one || two;
- }),
+ disabled$: getDisableWhenSelectionInTableObservable(accessor),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
diff --git a/packages/docs-thread-comment-ui/src/controllers/menu.ts b/packages/docs-thread-comment-ui/src/controllers/menu.ts
index a92f240884..cda2dee85c 100644
--- a/packages/docs-thread-comment-ui/src/controllers/menu.ts
+++ b/packages/docs-thread-comment-ui/src/controllers/menu.ts
@@ -34,7 +34,8 @@ export const shouldDisableAddComment = (accessor: IAccessor) => {
}
const range = textSelectionManagerService.getActiveTextRangeWithStyle();
- if (!range || range.collapsed) {
+
+ if (range == null || range.collapsed) {
return true;
}
@@ -73,6 +74,16 @@ export function ToolbarDocCommentMenuItemFactory(accessor: IAccessor): IMenuButt
title: 'threadCommentUI.panel.addComment',
tooltip: 'threadCommentUI.panel.addComment',
positions: [MenuPosition.TOOLBAR_START],
+ disabled$: new Observable(function (subscribe) {
+ const textSelectionService = accessor.get(TextSelectionManagerService);
+ const observer = textSelectionService.textSelection$.pipe(debounceTime(16)).subscribe(() => {
+ subscribe.next(shouldDisableAddComment(accessor));
+ });
+
+ return () => {
+ observer.unsubscribe();
+ };
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}