Skip to content

Commit ba55ea0

Browse files
authored
Merge pull request #4 from devforth/AdminForth/717
fix: add function to check if Quill content is empty before emitting …
2 parents f50e094 + 1ca7e70 commit ba55ea0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

custom/quillEditor.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ onMounted(() => {
289289
290290
});
291291
292+
function isQuillContentEmpty(html: string): boolean {
293+
const div = document.createElement('div');
294+
div.innerHTML = html;
295+
296+
div.querySelectorAll('br').forEach(br => br.remove());
297+
298+
div.querySelectorAll('p').forEach(p => {
299+
if (!p.textContent?.trim()) {
300+
p.remove();
301+
}
302+
});
303+
304+
const text = div.textContent?.trim();
305+
return !text;
306+
}
292307
293308
async function emitTextUpdate() {
294309
const editorHtml = quill.root.innerHTML;
@@ -311,9 +326,9 @@ async function emitTextUpdate() {
311326
lastText = html;
312327
313328
await (new Promise((resolve) => setTimeout(resolve, 0)));
314-
329+
const isEmpty = isQuillContentEmpty(html);
315330
dbg('⬆️ emit value suggestion-input', html);
316-
emit('update:value', html);
331+
emit('update:value', isEmpty ? '' : html);
317332
}
318333
319334
// Auto-Completion functions

0 commit comments

Comments
 (0)