Skip to content

Commit

Permalink
Merge branch 'master' into u/juliaroldi/list-bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi authored Nov 18, 2024
2 parents 7550ba3 + 91c25fb commit 5d9d5e3
Show file tree
Hide file tree
Showing 25 changed files with 1,132 additions and 892 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';
import { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom';
import { getSelectedSegmentsAndParagraphs, mergeTextSegments } from 'roosterjs-content-model-dom';
import type {
ContentModelSegmentFormat,
IEditor,
Expand Down Expand Up @@ -72,12 +72,18 @@ export function formatSegmentWithContentModel(
)
: false;

formatsAndSegments.forEach(([format, segment, paragraph]) =>
toggleStyleCallback(format, !isTurningOff, segment, paragraph)
);
formatsAndSegments.forEach(([format, segment, paragraph]) => {
toggleStyleCallback(format, !isTurningOff, segment, paragraph);
});

afterFormatCallback?.(model);

formatsAndSegments.forEach(([_, __, paragraph]) => {
if (paragraph) {
mergeTextSegments(paragraph);
}
});

if (isCollapsedSelection) {
context.newPendingFormat = segmentAndParagraphs[0][0].format;
editor.focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,7 @@ describe('applySegmentFormat', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
backgroundColor: undefined,
fontFamily: undefined,
fontSize: '10px',
fontWeight: undefined,
italic: true,
strikethrough: undefined,
superOrSubScriptSequence: undefined,
textColor: 'red',
underline: false,
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
backgroundColor: undefined,
fontFamily: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,7 @@ describe('setBackgroundColor', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
backgroundColor: 'red',
},
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
backgroundColor: 'red',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,7 @@ describe('setFontName', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
fontFamily: 'Arial',
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
fontFamily: 'Arial',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,7 @@ describe('setFontSize', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
fontSize: '10pt',
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
fontSize: '10pt',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,7 @@ describe('setTextColor', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
textColor: 'red',
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
textColor: 'red',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ describe('toggleBold', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
fontWeight: 'bold',
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
fontWeight: 'bold',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,7 @@ describe('toggleCode', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {},
isSelected: true,
code: {
format: {
fontFamily: 'monospace',
},
},
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {},
isSelected: true,
code: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ describe('toggleItalic', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
italic: true,
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
italic: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ describe('toggleStrikethrough', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
strikethrough: true,
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
strikethrough: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ describe('toggleSubscript', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
superOrSubScriptSequence: 'sub',
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
superOrSubScriptSequence: 'sub',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ describe('toggleSuperscript', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
superOrSubScriptSequence: 'super',
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
superOrSubScriptSequence: 'super',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ describe('toggleUnderline', () => {
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
underline: true,
},
isSelected: true,
},
{
segmentType: 'Text',
text: 'test',
text: 'testtest',
format: {
underline: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ function isIndexedSegment(node: Node): node is IndexedSegmentNode {
paragraph &&
paragraph.blockType == 'Paragraph' &&
Array.isArray(paragraph.segments) &&
Array.isArray(segments)
Array.isArray(segments) &&
segments.every(segment => paragraph.segments.includes(segment))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Unformatted line\n',
text: 'Unformatted line',
format: {
fontSize: '14px',
textColor: 'white',
Expand Down Expand Up @@ -1149,7 +1149,15 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Unformatted line\n',
text: 'Unformatted line',
format: {
fontSize: '14px',
textColor: 'white',
},
},
{
segmentType: 'Text',
text: '\n',
format: {
fontSize: '14px',
textColor: 'white',
Expand Down Expand Up @@ -1482,7 +1490,15 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Inline text\n',
text: 'Inline text',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
},
},
{
segmentType: 'Text',
text: '\n',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
Expand Down Expand Up @@ -1537,7 +1553,15 @@ describe('mergePasteContent', () => {
},
{
segmentType: 'Text',
text: 'Inline text\n',
text: 'Inline text',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
},
},
{
segmentType: 'Text',
text: '\n',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
Expand Down Expand Up @@ -1605,7 +1629,16 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Inline text\n',
text: 'Inline text',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
textColor: 'white',
},
},
{
segmentType: 'Text',
text: '\n',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
Expand Down Expand Up @@ -1653,7 +1686,16 @@ describe('mergePasteContent', () => {
{ segmentType: 'Text', text: 'Text in source', format: {} },
{
segmentType: 'Text',
text: 'Inline text\n',
text: 'Inline text',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
textColor: 'white',
},
},
{
segmentType: 'Text',
text: '\n',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
Expand Down
Loading

0 comments on commit 5d9d5e3

Please sign in to comment.