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(sheet-formula): store themeColor to reuse (#2079)

Konv Suu6c2e1d3225d2
diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.ts
index 48f9f03bc8..d50ba5334a 100644
--- a/packages/sheets-formula/src/controllers/prompt.controller.ts
+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts
@@ -920,6 +920,7 @@ export class PromptController extends Disposable {
private _buildTextRuns(sequenceNodes: Array<ISequenceNode | string>) {
const textRuns: ITextRun[] = [];
const refSelections: IRefSelection[] = [];
+ const themeColorMap = new Map<string, string>();
let refColorIndex = 0;
const offset = this._getCurrentBodyDataStreamAndOffset()?.offset || 0;
@@ -933,16 +934,20 @@ export class PromptController extends Disposable {
const { startIndex, endIndex, nodeType, token } = node;
let themeColor = '';
if (nodeType === sequenceNodeType.REFERENCE) {
- const colorIndex = refColorIndex % this._formulaRefColors.length;
- themeColor = this._formulaRefColors[colorIndex];
+ if (themeColorMap.has(token)) {
+ themeColor = themeColorMap.get(token)!;
+ } else {
+ const colorIndex = refColorIndex % this._formulaRefColors.length;
+ themeColor = this._formulaRefColors[colorIndex];
+ themeColorMap.set(token, themeColor);
+ refColorIndex++;
+ }
refSelections.push({
refIndex: i,
themeColor,
token,
});
-
- refColorIndex++;
} else if (nodeType === sequenceNodeType.NUMBER) {
themeColor = this._numberColor;
} else if (nodeType === sequenceNodeType.STRING) {