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(sheets-formula-ui): formula highlight display error when delete function name (#4871)

ZhangWeiadcd070793bc
diff --git a/packages/core/src/docs/data-model/text-x/build-utils/text-x-utils.ts b/packages/core/src/docs/data-model/text-x/build-utils/text-x-utils.ts
index 1cb5a89cde..918aa80512 100644
--- a/packages/core/src/docs/data-model/text-x/build-utils/text-x-utils.ts
+++ b/packages/core/src/docs/data-model/text-x/build-utils/text-x-utils.ts
@@ -14,12 +14,13 @@
* limitations under the License.
*/
+import type { Nullable } from '../../../../shared';
import type { ITextRange, ITextRangeParam } from '../../../../sheets/typedef';
import type { CustomRangeType, IDocumentBody, ITextRun } from '../../../../types/interfaces';
import type { DocumentDataModel } from '../../document-data-model';
import type { TextXAction } from '../action-types';
import type { TextXSelection } from '../text-x';
-import { type Nullable, Tools, UpdateDocsAttributeType } from '../../../../shared';
+import { Tools, UpdateDocsAttributeType } from '../../../../shared';
import { textDiff } from '../../../../shared/text-diff';
import { TextXActionType } from '../action-types';
import { TextX } from '../text-x';
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
index 6a558ffb49..279b868d1b 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
@@ -153,10 +153,12 @@ export function FormulaEditor(props: IFormulaEditorProps) {
const highlight = useEvent((text: string, isNeedResetSelection: boolean = true, isEnd?: boolean, newSelections?: ITextRange[]) => {
if (!editorRef.current) return;
highTextRef.current = text;
- const sequenceNodes = getFormulaToken(text[0] === '=' ? text.slice(1) : '');
+ const formulaStr = text[0] === '=' ? text.slice(1) : '';
+ const sequenceNodes = getFormulaToken(formulaStr);
+ const parsedFormula = sequenceNodes.reduce((pre, cur) => (typeof cur === 'object' ? `${pre}${cur.token}` : `${pre}${cur}`), '');
const ranges = highlightDoc(
editorRef.current,
- sequenceNodes,
+ parsedFormula === formulaStr ? sequenceNodes : [],
isNeedResetSelection,
newSelections
);