Skip to content

Commit

Permalink
Fix combineFormats with multiple values repeated, closes #3336
Browse files Browse the repository at this point in the history
Co-authored-by: Dorotea Franjić <dorotea.franjic@intellegens.hr>
  • Loading branch information
Dora1604 and Dorotea Franjić committed Jun 10, 2022
1 parent 271c47d commit 2e138a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ function combineFormats(formats, combined) {
} else if (Array.isArray(combined[name])) {
if (combined[name].indexOf(formats[name]) < 0) {
merged[name] = combined[name].concat([formats[name]]);
} else {
// If style already exists, don't add to an array, but don't lose other styles
merged[name] = combined[name];
}
} else {
merged[name] = [combined[name], formats[name]];
Expand Down
35 changes: 35 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,41 @@ describe('Editor', function() {
});
});

it('across leaves repeated', function() {
const editor = this.initialize(
Editor,
`
<h1>
<strong class="ql-size-small"><em>01</em></strong>
<em class="ql-size-large"><u>23</u></em>
<em class="ql-size-huge"><u>45</u></em>
<em class="ql-size-small"><u>45</u></em>
</h1>
`,
);
expect(editor.getFormat(1, 4)).toEqual({
italic: true,
header: 1,
size: ['small', 'large', 'huge'],
});
});

it('across lines repeated', function() {
const editor = this.initialize(
Editor,
`
<h1 class="ql-align-right"><em>01</em></h1>
<h1 class="ql-align-center"><em>34</em></h1>
<h1 class="ql-align-right"><em>36</em></h1>
<h1 class="ql-align-center"><em>33</em></h1>
`,
);
expect(editor.getFormat(1, 3)).toEqual({
italic: true,
header: 1,
align: ['right', 'center'],
});
});
it('across lines', function() {
const editor = this.initialize(
Editor,
Expand Down

0 comments on commit 2e138a0

Please sign in to comment.