Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/quill/src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CursorBlot from '../blots/cursor.js';
import type Scroll from '../blots/scroll.js';
import TextBlot, { escapeText } from '../blots/text.js';
import { Range } from './selection.js';
import { Parchment } from './quill.js';

const ASCII = /^[ -~]*$/;

Expand Down Expand Up @@ -173,13 +174,20 @@ class Editor {
const [blot] = path;
if (blot instanceof Block) {
lines.push(blot);
} else if (blot instanceof LeafBlot) {
} else if (blot instanceof LeafBlot && !(blot instanceof BlockEmbed)) {
leaves.push(blot);
}
});
} else {
lines = this.scroll.lines(index, length);
leaves = this.scroll.descendants(LeafBlot, index, length);
lines = this.scroll
.lines(index, length)
.filter((line) => !(line instanceof BlockEmbed));
leaves = this.scroll.descendants(
(blot: Parchment.Blot) =>
blot instanceof Parchment.LeafBlot && !(blot instanceof BlockEmbed),
index,
length,
) as Parchment.LeafBlot[];
}
const [lineFormats, leafFormats] = [lines, leaves].map((blots) => {
const blot = blots.shift();
Expand Down
29 changes: 29 additions & 0 deletions packages/quill/test/unit/core/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,35 @@ describe('Editor', () => {
align: ['right', 'center'],
});
});

test('Embed in range', () => {
const editor = createEditor(
`
<h1 class="ql-align-right"><em>01</em></h1>
<h1 class="ql-align-right"><em><img src="#" /></em></h1>
<h1 class="ql-align-center"><em>34</em></h1>
`,
);
expect(editor.getFormat(1, 3)).toEqual({
italic: true,
header: 1,
align: ['right', 'center'],
});
});
test('BlockEmbed in range', () => {
const editor = createEditor(
`
<h1 class="ql-align-right"><em>01</em></h1>
<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
<h1 class="ql-align-center"><em>34</em></h1>
`,
);
expect(editor.getFormat(1, 3)).toEqual({
italic: true,
header: 1,
align: ['right', 'center'],
});
});
});

describe('getHTML', () => {
Expand Down