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: inline menu highlight (#1401)

Ran Luob3d25e932844
diff --git a/packages/core/src/sheets/__tests__/ranges.spec.ts b/packages/core/src/sheets/__tests__/ranges.spec.ts
new file mode 100644
index 0000000000..071cd60d00
--- /dev/null
+++ b/packages/core/src/sheets/__tests__/ranges.spec.ts
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * 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 { describe, expect, it } from 'vitest';
+import { isAllFormatInTextRuns } from '../range';
+import type { IDocumentBody } from '../../types/interfaces';
+import { BooleanNumber } from '../../types/enum';
+
+describe('Test isAllFormatInTextRuns', () => {
+ it('should return true when all content is bold', () => {
+ const body: IDocumentBody = {
+ dataStream: 'hello\r\n',
+ textRuns: [{
+ st: 0,
+ ed: 5,
+ ts: { bl: BooleanNumber.TRUE },
+ }],
+ };
+
+ expect(isAllFormatInTextRuns('bl', body)).toBe(BooleanNumber.TRUE);
+ });
+
+ it('should return false when any content is not bold', () => {
+ const body: IDocumentBody = {
+ dataStream: 'hello\r\n',
+ textRuns: [{
+ st: 0,
+ ed: 4,
+ ts: { bl: BooleanNumber.TRUE },
+ }],
+ };
+
+ expect(isAllFormatInTextRuns('bl', body)).toBe(BooleanNumber.FALSE);
+ });
+});
diff --git a/packages/core/src/sheets/range.ts b/packages/core/src/sheets/range.ts
index 67809f83a8..8b4720b12f 100644
--- a/packages/core/src/sheets/range.ts
+++ b/packages/core/src/sheets/range.ts
@@ -47,8 +47,8 @@ export interface IRangeDependencies {
getStyles(): Readonly<Styles>;
}
-function isAllFormatInTextRuns(key: keyof IStyleBase, body: IDocumentBody): BooleanNumber {
- const { textRuns = [], paragraphs = [], sectionBreaks = [] } = body;
+export function isAllFormatInTextRuns(key: keyof IStyleBase, body: IDocumentBody): BooleanNumber {
+ const { textRuns = [] } = body;
let len = 0;
@@ -84,7 +84,9 @@ function isAllFormatInTextRuns(key: keyof IStyleBase, body: IDocumentBody): Bool
}
// Ensure textRuns cover all content.
- return body.dataStream.length - paragraphs.length - sectionBreaks.length === len ? BooleanNumber.TRUE : BooleanNumber.FALSE;
+ const index = body.dataStream.indexOf('\r\n');
+
+ return index === len ? BooleanNumber.TRUE : BooleanNumber.FALSE;
}
/**
@@ -459,13 +461,13 @@ export class Range {
: FontItalic.NORMAL;
}
- return this.getFontStyles()[0][0];
+ return this._getFontStyles()[0][0];
}
/**
* Returns the font styles of the cells in the range.
*/
- private getFontStyles(): FontItalic[][] {
+ private _getFontStyles(): FontItalic[][] {
return this._getStyles('it') as FontItalic[][];
}