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.

chore: fix icon disable status when edit not focus (#5206)

ybzky59a4123bbcaf
diff --git a/packages/docs-ui/src/services/clipboard/clipboard.service.ts b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
index ce8118c499..7565cc7998 100644
--- a/packages/docs-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
@@ -150,6 +150,10 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
if (!html && !text && files.length) {
html = await this._createImagePasteHtml(files);
}
+ if (!html && !text) {
+ this._logService.warn('[DocClipboardController] html and text cannot be both empty!');
+ return false;
+ }
const partDocData = this._genDocDataFromHtmlAndText(html, text, docUnitId);
// Paste in sheet editing mode without paste style, so we give textRuns empty array;
if (docUnitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
diff --git a/packages/sheets-table-ui/src/views/menu.ts b/packages/sheets-table-ui/src/views/menu.ts
index fe0289db5f..73f5b29c2b 100644
--- a/packages/sheets-table-ui/src/views/menu.ts
+++ b/packages/sheets-table-ui/src/views/menu.ts
@@ -24,17 +24,19 @@ import { MenuItemType } from '@univerjs/ui';
import { of, switchMap } from 'rxjs';
import { OpenTableSelectorOperation } from '../commands/operations/open-table-selector.operation';
import { TABLE_TOOLBAR_BUTTON } from '../const';
+import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
export const SHEET_TABLE_CONTEXT_INSERT_MENU_ID = 'sheet.table.context-insert_menu-id';
export const SHEET_TABLE_CONTEXT_REMOVE_MENU_ID = 'sheet.table.context-remove_menu-id';
-export function sheetTableToolbarInsertMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sheetTableToolbarInsertMenuFactory(accessor: IAccessor): IMenuItem {
return {
id: OpenTableSelectorOperation.id,
type: MenuItemType.BUTTON,
icon: TABLE_TOOLBAR_BUTTON,
tooltip: 'sheets-table.title',
title: 'sheets-table.title',
+ disabled$: getCurrentRangeDisable$(accessor, {}, true),
};
}
diff --git a/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts b/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
index 02860e0b8b..aa03190fa1 100644
--- a/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
+++ b/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
@@ -17,7 +17,7 @@
import type { IAccessor, Workbook } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, IContextService, IPermissionService, IUniverInstanceService, RANGE_TYPE, Rectangle, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { RangeProtectionCache, RangeProtectionRuleModel, SheetsSelectionsService, UnitAction, WorkbookCreateProtectPermission, WorkbookEditablePermission, WorkbookManageCollaboratorPermission, WorksheetDeleteProtectionPermission, WorksheetManageCollaboratorPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
-import { combineLatest, map, merge, of, startWith, switchMap } from 'rxjs';
+import { combineLatest, map, merge, of, shareReplay, startWith, switchMap } from 'rxjs';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
export function getAddPermissionHidden$(accessor: IAccessor) {
@@ -213,8 +213,14 @@ export function getAddPermissionDisableBase$(accessor: IAccessor) {
const userManagerService = accessor.get(UserManagerService);
const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
const contextService = accessor.get(IContextService);
- const formulaEditorFocus$ = contextService.subscribeContextValue$(FOCUSING_FX_BAR_EDITOR);
- const editorVisible$ = editorBridgeService?.visible$ ?? of(null);
+ const formulaEditorFocus$ = contextService.subscribeContextValue$(FOCUSING_FX_BAR_EDITOR).pipe(
+ startWith(false),
+ shareReplay(1)
+ );
+ const editorVisible$ = editorBridgeService?.visible$.pipe(
+ startWith(null),
+ shareReplay(1)
+ ) ?? of(null);
return combineLatest([workbook$, userManagerService.currentUser$, editorVisible$, formulaEditorFocus$]).pipe(
switchMap(([workbook, _, visible, formulaEditorFocus]) => {