javascriptvue.jstiptap

tiptap: make isEmpty return true when the editor only contains whitespaces and new lines (LITERALLY empty)


this isEmpty still returns true when the editor contains only whitespace(s) (and alongside with new lines) :

import { EditorContent, Editor } from "@tiptap/vue-3";

const editor = new Editor({
  // ...
})

const isEmpty = () => !editor.state.doc.textContent.length;

https://codesandbox.io/s/tiptap-vue-forked-gpwrpn

P.S. I don't use editor.isEmpty because it's unreliable, views whitespaces and new lines as not empty


Solution

  • You could use the trim method on your textContent :

    const isEmpty = () => !editor.state.doc.textContent.trim().length;