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
fix(sheets): inline menu highlight error (#1388)
Ran Luo8ca9cc11ecbf
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex d42c63275b..1b1d46118c 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -34,6 +34,7 @@"Heiti","Hiragino","Hlookup",+ "hoverable","ilvl","IRPC","Jamo",diff --git a/packages/core/src/sheets/range.ts b/packages/core/src/sheets/range.tsindex 03d5f721e4..67809f83a8 100644--- a/packages/core/src/sheets/range.ts+++ b/packages/core/src/sheets/range.ts@@ -22,13 +22,13 @@ import { BooleanNumber, FontItalic, FontWeight } from '../types/enum';import type {IBorderData,ICellData,+ IDocumentBody,IDocumentData,IRange,IStyleBase,IStyleData,ITextDecoration,ITextRotation,- ITextRun,} from '../types/interfaces';import type { Styles } from './styles';import type { Worksheet } from './worksheet';@@ -47,9 +47,13 @@ export interface IRangeDependencies {getStyles(): Readonly<Styles>;}-function isAllFormatInTextRuns(key: keyof IStyleBase, textRuns: ITextRun[]): BooleanNumber {+function isAllFormatInTextRuns(key: keyof IStyleBase, body: IDocumentBody): BooleanNumber {+ const { textRuns = [], paragraphs = [], sectionBreaks = [] } = body;++ let len = 0;+for (const textRun of textRuns) {- const { ts = {} } = textRun;+ const { ts = {}, st, ed } = textRun;if (ts[key] == null) {return BooleanNumber.FALSE;@@ -75,9 +79,12 @@ function isAllFormatInTextRuns(key: keyof IStyleBase, textRuns: ITextRun[]): Boodefault:throw new Error(`unknown style key: ${key} in IStyleBase`);}++ len += ed - st;}- return BooleanNumber.TRUE;+ // Ensure textRuns cover all content.+ return body.dataStream.length - paragraphs.length - sectionBreaks.length === len ? BooleanNumber.TRUE : BooleanNumber.FALSE;}/**@@ -361,8 +368,8 @@ export class Range {getUnderline(): ITextDecoration {const { p } = this.getValue() ?? {};- if (p && Array.isArray(p.body?.textRuns)) {- return isAllFormatInTextRuns('ul', p.body?.textRuns!) === BooleanNumber.TRUE+ if (p && Array.isArray(p.body?.textRuns) && p.body.textRuns.length > 0) {+ return isAllFormatInTextRuns('ul', p.body) === BooleanNumber.TRUE? {s: BooleanNumber.TRUE,}@@ -394,8 +401,8 @@ export class Range {getStrikeThrough(): ITextDecoration {const { p } = this.getValue() ?? {};- if (p && Array.isArray(p.body?.textRuns)) {- return isAllFormatInTextRuns('st', p.body?.textRuns!) === BooleanNumber.TRUE+ if (p && Array.isArray(p.body?.textRuns) && p.body.textRuns.length > 0) {+ return isAllFormatInTextRuns('st', p.body) === BooleanNumber.TRUE? {s: BooleanNumber.TRUE,}@@ -446,8 +453,8 @@ export class Range {getFontStyle(): FontItalic {const { p } = this.getValue() ?? {};- if (p && Array.isArray(p.body?.textRuns)) {- return isAllFormatInTextRuns('it', p.body?.textRuns!) === BooleanNumber.TRUE+ if (p && Array.isArray(p.body?.textRuns) && p.body.textRuns.length > 0) {+ return isAllFormatInTextRuns('it', p.body) === BooleanNumber.TRUE? FontItalic.ITALIC: FontItalic.NORMAL;}@@ -471,19 +478,19 @@ export class Range {getFontWeight(): FontWeight {const { p } = this.getValue() ?? {};- if (p && Array.isArray(p.body?.textRuns)) {- return isAllFormatInTextRuns('bl', p.body?.textRuns!) === BooleanNumber.TRUE+ if (p && Array.isArray(p.body?.textRuns) && p.body.textRuns.length > 0) {+ return isAllFormatInTextRuns('bl', p.body) === BooleanNumber.TRUE? FontWeight.BOLD: FontWeight.NORMAL;}- return this.getFontWeights()[0][0];+ return this._getFontWeights()[0][0];}/*** Returns the font weights of the cells in the range.*/- private getFontWeights(): FontWeight[][] {+ private _getFontWeights(): FontWeight[][] {return this._getStyles('bl') as FontWeight[][];}