fxmontigny / quill-image-upload

A module for Quill rich text editor to upload images to be selected from toolbar editor.
107 stars 43 forks source link

Should be able to insert image to the beginning of content #16

Open caasi opened 5 years ago

caasi commented 5 years ago

Current code will fallback to this.quill.getLength() when you move your cursor to the beginning of content.

insert(dataUrl) {
  const index =
    (this.quill.getSelection() || {}).index || this.quill.getLength();
  this.quill.insertEmbed(index, 'image', dataUrl, 'user');
}

Check the result of getSelection may be a better solution.

insert(dataUrl) {
  const selection = this.quill.getSelection();
  const index = selection
    ? selection.index
    : this.quill.getLength();
  this.quill.insertEmbed(index, 'image', dataUrl, 'user');
}
singleseeker commented 4 years ago

@caasi Good job, You should give a PR to this project.