Skip to content

Commit

Permalink
Merge branch 'quilljs:develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rockwotj authored Dec 6, 2021
2 parents 69291f7 + 7b3263b commit 1d2b919
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions blots/scroll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scope, ScrollBlot, ContainerBlot } from 'parchment';
import { Scope, ScrollBlot, ContainerBlot, LeafBlot } from 'parchment';
import Emitter from '../core/emitter';
import Block, { BlockEmbed } from './block';
import Break from './break';
Expand Down Expand Up @@ -103,7 +103,11 @@ class Scroll extends ScrollBlot {
}

leaf(index) {
return this.path(index).pop() || [null, -1];
const last = this.path(index).pop();
if (!last || !(last[0] instanceof LeafBlot)) {
return [null, -1];
}
return last;
}

line(index) {
Expand Down
1 change: 1 addition & 0 deletions core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class Quill {
} else {
bounds = this.selection.getBounds(index.index, index.length);
}
if (!bounds) return null;
const containerBounds = this.container.getBoundingClientRect();
return {
bottom: bounds.bottom - containerBounds.top,
Expand Down
8 changes: 8 additions & 0 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ class Selection {
let side = 'left';
let rect;
if (node instanceof Text) {
// Return null if the text node is empty because it is
// not able to get a useful client rect:
// https://github.com/w3c/csswg-drafts/issues/2514.
// Empty text nodes are most likely caused by TextBlot#optimize()
// not getting called when editor content changes.
if (!node.data.length) {
return null;
}
if (offset < node.data.length) {
range.setStart(node, offset);
range.setEnd(node, offset + 1);
Expand Down
9 changes: 9 additions & 0 deletions test/unit/core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,5 +630,14 @@ describe('Selection', function() {
this.bounds = selection.getBounds(0, 10);
}).not.toThrow();
});

it('empty container', function() {
const selection = this.initialize(
Selection,
'<table><tr><td data-row="a">a</td></tr></table>',
);
this.quill.updateContents([{ retain: 1 }, { insert: '\n' }]);
expect(selection.getBounds(2, 0)).toEqual(null);
});
});
});

0 comments on commit 1d2b919

Please sign in to comment.