From 8d4f3267b68ecccd8810022b33b13bed3087ed16 Mon Sep 17 00:00:00 2001 From: wpxp123456 <2677556700@qq.com> Date: Sat, 8 Nov 2025 12:00:21 +0800 Subject: [PATCH] fix: fix two alert pop-ups appearing simultaneously (#6108) --- .../formula-alert-render.controller.ts | 3 +- .../numfmt-alert-render.controller.ts | 27 +++++----- .../force-string-alert-render.controller.ts | 50 ++++++++++++------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/packages/sheets-formula-ui/src/controllers/formula-alert-render.controller.ts b/packages/sheets-formula-ui/src/controllers/formula-alert-render.controller.ts index 38c2383674..af1ae40d9d 100644 --- a/packages/sheets-formula-ui/src/controllers/formula-alert-render.controller.ts +++ b/packages/sheets-formula-ui/src/controllers/formula-alert-render.controller.ts @@ -63,7 +63,7 @@ export class FormulaAlertRenderController extends Disposable implements IRenderM const workbook = this._context.unit; const worksheet = workbook.getActiveSheet(); - if (!worksheet) return; + if (!worksheet) return this._hideAlert(); const cellData = worksheet.getCell(cellPos.location.row, cellPos.location.col); @@ -92,6 +92,7 @@ export class FormulaAlertRenderController extends Disposable implements IRenderM currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId ) { + this._hideAlert(); return; } diff --git a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts index 2981f75ec8..9ac3806adf 100644 --- a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts +++ b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts @@ -51,7 +51,7 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo const location = cellPos.location; const workbook = this._context.unit; const worksheet = workbook.getActiveSheet(); - if (!worksheet) return; + if (!worksheet) return this._hideAlert(); const unitId = location.unitId; const sheetId = location.subUnitId; @@ -82,20 +82,17 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo return; } - const currentAlerts = this._cellAlertManagerService.currentAlert; - - for (const [_, value] of currentAlerts.entries()) { - const currentLoc = value?.alert?.location; - - if ( - currentLoc && - currentLoc.row === location.row && - currentLoc.col === location.col && - currentLoc.subUnitId === location.subUnitId && - currentLoc.unitId === location.unitId - ) { - return; - } + const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY); + const currentLoc = currentAlert?.alert?.location; + if ( + currentLoc && + currentLoc.row === location.row && + currentLoc.col === location.col && + currentLoc.subUnitId === location.subUnitId && + currentLoc.unitId === location.unitId + ) { + this._hideAlert(); + return; } this._cellAlertManagerService.showAlert({ diff --git a/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts b/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts index 3786d489b0..29525ab5ed 100644 --- a/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts +++ b/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts @@ -17,7 +17,7 @@ import type { Workbook } from '@univerjs/core'; import type { IRenderContext, IRenderModule } from '@univerjs/engine-render'; import type { IUniverSheetsUIConfig } from './config.schema'; -import { CellValueType, Disposable, IConfigService, Inject, isRealNum, LocaleService, numfmt } from '@univerjs/core'; +import { CellValueType, Disposable, IConfigService, Inject, isRealNum, isTextFormat, LocaleService, numfmt } from '@univerjs/core'; import { IZenZoneService } from '@univerjs/ui'; import { CellAlertManagerService, CellAlertType } from '../services/cell-alert-manager.service'; import { HoverManagerService } from '../services/hover-manager.service'; @@ -50,11 +50,26 @@ export class ForceStringAlertRenderController extends Disposable implements IRen const workbook = this._context.unit; const worksheet = workbook.getActiveSheet(); - if (!worksheet) return; + if (!worksheet) return this._hideAlert(); const cellData = worksheet.getCell(location.row, location.col); - if (!cellData || cellData.v === null || cellData.v === undefined) return; + if (!cellData || cellData.v === null || cellData.v === undefined) return this._hideAlert(); + + let numfmtValue; + + if (cellData?.s) { + const style = workbook.getStyles().get(cellData.s); + if (style?.n) { + numfmtValue = style.n; + } + } + + // If the cell has text format, follow the logic of text format and do not show the force string alert. + if (isTextFormat(numfmtValue?.pattern)) { + this._hideAlert(); + return; + } /** * If the cell type is string or force string, and the value is a pure number or a string that can be converted to a number, show the force string alert. @@ -68,27 +83,24 @@ export class ForceStringAlertRenderController extends Disposable implements IRen (cellData.t === CellValueType.FORCE_STRING || cellData.t === CellValueType.STRING) && (isRealNum(cellData.v) || (typeof cellData.v === 'string' && numfmt.parseNumber(cellData.v))) ) { - const currentAlerts = this._cellAlertManagerService.currentAlert; - - for (const [_, value] of currentAlerts.entries()) { - const currentLoc = value?.alert?.location; - - if ( - currentLoc && - currentLoc.row === location.row && - currentLoc.col === location.col && - currentLoc.subUnitId === location.subUnitId && - currentLoc.unitId === location.unitId - ) { - return; - } - } - // If the user has disabled the force string alert, do not show it if (this._configService.getConfig(SHEETS_UI_PLUGIN_CONFIG_KEY)?.disableForceStringAlert) { return; } + const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY); + const currentLoc = currentAlert?.alert?.location; + if ( + currentLoc && + currentLoc.row === cellPos.location.row && + currentLoc.col === cellPos.location.col && + currentLoc.subUnitId === cellPos.location.subUnitId && + currentLoc.unitId === cellPos.location.unitId + ) { + this._hideAlert(); + return; + } + this._cellAlertManagerService.showAlert({ type: CellAlertType.ERROR, title: this._localeService.t('info.error'),