Skip to content

Commit

Permalink
fix image positioning
Browse files Browse the repository at this point in the history
fixes #670
  • Loading branch information
jhchen committed May 16, 2016
1 parent 1ee65b1 commit 4b5a815
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ class Selection {
offset = 0;
} else if (node.childNodes.length === offset) {
node = node.lastChild;
offset = node instanceof Text ? node.data.length : node.childNodes.length;
offset = node instanceof Text ? node.data.length : node.childNodes.length + 1;
} else {
break;
}
}
position.node = node, position.offset = offset;
});
debug.info('getNativeRange', range);
return range;
}

Expand Down
1 change: 1 addition & 0 deletions modules/image-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ImageTooltip extends Module {
let index = range.index + range.length;
this.quill.insertEmbed(index, ImageBlot.blotName, this.textbox.value, Quill.sources.USER);
this.quill.setSelection(index + 1, Quill.sources.SILENT);
this.textbox.value = '';
this.hide();
}

Expand Down
11 changes: 11 additions & 0 deletions test/unit/core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ describe('Selection', function() {
expect(selection.hasFocus()).toBe(true);
});

it('single embed', function() {
let selection = this.initialize(Selection,
`<p><img src="/assets/favicon.png"></p>`
);
let expected = new Range(1, 0);
selection.setRange(expected);
let [range, ] = selection.getRange();
expect(range).toEqual(expected);
expect(selection.hasFocus()).toBe(true);
});

it('between embeds', function() {
let selection = this.initialize(Selection, `
<p>
Expand Down

0 comments on commit 4b5a815

Please sign in to comment.