Skip to content

Commit

Permalink
fix: inline menu highlight (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Feb 24, 2024
1 parent ba51971 commit b3d25e9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
48 changes: 48 additions & 0 deletions 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);
});
});
12 changes: 7 additions & 5 deletions packages/core/src/sheets/range.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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[][];
}

Expand Down

0 comments on commit b3d25e9

Please sign in to comment.