Skip to content

Commit

Permalink
Fix #2825 (#2839)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Oct 22, 2024
1 parent e109e8e commit 64ba856
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function deleteExpandedSelection(
// so we can put cursor here after delete
paragraph = block;
insertMarkerIndex = indexes[0];
markerFormat = getSegmentTextFormat(segments[0]);
markerFormat = getSegmentTextFormat(segments[0], true /*includingBIU*/);

context.lastParagraph = paragraph;
context.lastTableContext = tableContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ import type {
/**
* Get the text format of a segment, this function will return only format that is applicable to text
* @param segment The segment to get format from
* @param includingBIU When pass true, also get Bold/Italic/Underline format
* @returns
*/
export function getSegmentTextFormat(
segment: ReadonlyContentModelSegment
segment: ReadonlyContentModelSegment,
includingBIU?: boolean
): ContentModelSegmentFormat {
const { fontFamily, fontSize, textColor, backgroundColor, letterSpacing, lineHeight } =
segment?.format ?? {};

const format = segment.format ?? {};
const textFormat: ContentModelSegmentFormat = {
fontFamily,
fontSize,
textColor,
backgroundColor,
letterSpacing,
lineHeight,
fontFamily: format.fontFamily,
fontSize: format.fontSize,
textColor: format.textColor,
backgroundColor: format.backgroundColor,
letterSpacing: format.letterSpacing,
lineHeight: format.lineHeight,
fontWeight: includingBIU ? format.fontWeight : undefined,
italic: includingBIU ? format.italic : undefined,
underline: includingBIU ? format.underline : undefined,
};

return removeUndefinedValues(textFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('getSegmentTextFormat', () => {
backgroundColor: 'blue',
letterSpacing: '1px',
lineHeight: '1.5',
fontWeight: 'bold',
});
expect(getSegmentTextFormat(segment)).toEqual({
fontFamily: 'Arial',
Expand Down Expand Up @@ -49,4 +50,29 @@ describe('getSegmentTextFormat', () => {
letterSpacing: '1px',
});
});

it('get format including B/I/U', () => {
const segment = createText('test', {
fontFamily: 'Arial',
fontSize: '12px',
textColor: 'red',
backgroundColor: 'blue',
letterSpacing: '1px',
lineHeight: '1.5',
fontWeight: 'bold',
italic: true,
underline: false,
});
expect(getSegmentTextFormat(segment, true)).toEqual({
fontFamily: 'Arial',
fontSize: '12px',
textColor: 'red',
backgroundColor: 'blue',
letterSpacing: '1px',
lineHeight: '1.5',
fontWeight: 'bold',
italic: true,
underline: false,
});
});
});

0 comments on commit 64ba856

Please sign in to comment.