attoae / quill-table-better

A module that enhances the table functionality of Quill.
MIT License
20 stars 4 forks source link

[Bug] Table cannot be displayed when edit again #12

Open jasperliu911 opened 2 weeks ago

jasperliu911 commented 2 weeks ago

After the table is saved, it cannot be displayed when it is edited and displayed again

企业微信截图_84502787-5206-4a49-814b-bb1f1fd1dec3

When edit showing

image
attoae commented 2 weeks ago
const delta = quill.clipboard.convert({
  html,
  text: '\n'
})
const [range] = quill.selection.getRange();
quill.updateContents(delta, Quill.sources.USER);
quill.setSelection(
  delta.length() - range.length,
  Quill.sources.SILENT,
);
quill.scrollIntoView();

Initialize using the above method.

jasperliu911 commented 2 weeks ago

Can you tell me specifically where this code should be placed? Because I am using the npm package form. After passing the html value of the table to the Richtext, I initialize this code and find that although this problem is solved, I cannot insert a table again, and the table cannot be fully displayed in the output html.

attoae commented 2 weeks ago

Do you dependencies on react-quill or vue-quill or other?

attoae commented 2 weeks ago

If it weren't for the abov. You can refer to the following code (Not HTML assignment, use this method after creating an editor instance):

const quill = new Quill('#root', options);
const delta = quill.clipboard.convert({
  html,
  text: '\n'
})
const [range] = quill.selection.getRange();
quill.updateContents(delta, Quill.sources.USER);
quill.setSelection(
  delta.length() - range.length,
  Quill.sources.SILENT,
);
quill.scrollIntoView();
jasperliu911 commented 2 weeks ago

Our actual use may be more complicated than the demo. We did this code after getting the html when initializing the rich text component and when listening to html changes. The problem was temporarily solved. But another problem arose, that is, the table could not be displayed normally when inserted for the second time. We temporarily solved the problem by replace the span tag in the table in the html, but it seems that it did not solve it fundamentally.

dustinormond commented 1 day ago

I did a workaround to get it working. Here is my code:

const html = $(quillID).html();
$(quillID).html("");
const quillEditor = new Quill(quillID, options);
const delta = quillEditor.clipboard.convert({ html })
quillEditor.updateContents(delta, Quill.sources.USER);