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
feat(cell-popup): hide cell popup while editing (#6146)
WEI ZHANG4dbb8cd6fb72
diff --git a/packages/sheets-ui/src/controllers/cell-popup-editor.controller.ts b/packages/sheets-ui/src/controllers/cell-popup-editor.controller.tsnew file mode 100644index 0000000000..d05b7409e0--- /dev/null+++ b/packages/sheets-ui/src/controllers/cell-popup-editor.controller.ts@@ -0,0 +1,55 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Workbook } from '@univerjs/core';+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';+import { Disposable, Inject } from '@univerjs/core';+import { filter } from 'rxjs';+import { CellPopupManagerService } from '../services/cell-popup-manager.service';+import { IEditorBridgeService } from '../services/editor-bridge.service';++/**+ * Controller to hide cell popups when entering edit mode.+ * This ensures that popups don't overlap with the cell editor.+ */+export class CellPopupEditorController extends Disposable implements IRenderModule {+ constructor(+ private readonly _context: IRenderContext<Workbook>,+ @IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,+ @Inject(CellPopupManagerService) private readonly _cellPopupManagerService: CellPopupManagerService+ ) {+ super();+ this._initEditorVisibleListener();+ }++ private _initEditorVisibleListener(): void {+ this.disposeWithMe(+ this._editorBridgeService.visible$.pipe(+ filter((params) => params.visible)+ ).subscribe(() => {+ const editCellState = this._editorBridgeService.getEditLocation();+ if (editCellState) {+ this._cellPopupManagerService.hidePopup(+ editCellState.unitId,+ editCellState.sheetId,+ editCellState.row,+ editCellState.column+ );+ }+ })+ );+ }+}diff --git a/packages/sheets-ui/src/mobile-plugin.ts b/packages/sheets-ui/src/mobile-plugin.tsindex 375e922535..2e0fb92596 100644--- a/packages/sheets-ui/src/mobile-plugin.ts+++ b/packages/sheets-ui/src/mobile-plugin.ts@@ -29,6 +29,7 @@ import { AutoHeightController } from './controllers/auto-height.controller';import { AutoWidthController } from './controllers/auto-width.controller';import { CellAlertRenderController } from './controllers/cell-alert.controller';import { CellCustomRenderController } from './controllers/cell-custom-render.controller';+import { CellPopupEditorController } from './controllers/cell-popup-editor.controller';import { SheetCheckboxController } from './controllers/checkbox.controller';import { SheetClipboardController } from './controllers/clipboard/clipboard.controller';import { defaultPluginConfig, SHEETS_UI_PLUGIN_CONFIG_KEY } from './controllers/config.schema';@@ -260,6 +261,7 @@ export class UniverSheetsMobileUIPlugin extends Plugin {[FormatPainterRenderController],[ClipboardRenderController],[CellAlertRenderController],+ [CellPopupEditorController],[ForceStringAlertRenderController],[MarkSelectionRenderController],[HoverRenderController],diff --git a/packages/sheets-ui/src/plugin.ts b/packages/sheets-ui/src/plugin.tsindex 199bc16316..7fc136b28f 100644--- a/packages/sheets-ui/src/plugin.ts+++ b/packages/sheets-ui/src/plugin.ts@@ -29,6 +29,7 @@ import { AutoHeightController } from './controllers/auto-height.controller';import { AutoWidthController } from './controllers/auto-width.controller';import { CellAlertRenderController } from './controllers/cell-alert.controller';import { CellCustomRenderController } from './controllers/cell-custom-render.controller';+import { CellPopupEditorController } from './controllers/cell-popup-editor.controller';import { SheetCheckboxController } from './controllers/checkbox.controller';import { SheetClipboardController } from './controllers/clipboard/clipboard.controller';import { defaultPluginConfig, SHEETS_UI_PLUGIN_CONFIG_KEY } from './controllers/config.schema';@@ -263,6 +264,7 @@ export class UniverSheetsUIPlugin extends Plugin {[FormatPainterRenderController],[ClipboardRenderController],[CellAlertRenderController],+ [CellPopupEditorController],[ForceStringAlertRenderController],[MarkSelectionRenderController],[HoverRenderController],diff --git a/packages/sheets-ui/src/services/cell-popup-manager.service.ts b/packages/sheets-ui/src/services/cell-popup-manager.service.tsindex 0a74b7ea68..0daaa255a6 100644--- a/packages/sheets-ui/src/services/cell-popup-manager.service.ts+++ b/packages/sheets-ui/src/services/cell-popup-manager.service.ts@@ -143,4 +143,43 @@ export class CellPopupManagerService extends Disposable {const subUnitMap = this._ensureCellPopupMap(unitId, subUnitId);return subUnitMap.getValue(row, col)?.[direction]?.popups || [];}++ hidePopup(unitId: string, subUnitId: string, row: number, col: number) {+ const subUnitMap = this._ensureCellPopupMap(unitId, subUnitId);+ const cache = subUnitMap.getValue(row, col);+ if (!cache) {+ return;+ }++ // Hide horizontal popups+ if (cache.horizontal) {+ cache.horizontal.disposable?.dispose();+ cache.horizontal = undefined;+ this._change$.next({+ unitId,+ subUnitId,+ row,+ col,+ direction: 'horizontal',+ });+ }++ // Hide vertical popups+ if (cache.vertical) {+ cache.vertical.disposable?.dispose();+ cache.vertical = undefined;+ this._change$.next({+ unitId,+ subUnitId,+ row,+ col,+ direction: 'vertical',+ });+ }++ // Clear the cache if both directions are empty+ if (!cache.horizontal && !cache.vertical) {+ subUnitMap.realDeleteValue(row, col);+ }+ }}