Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal Rule adds empty line #1665

Closed
wmonecke opened this issue Jul 30, 2021 · 3 comments · Fixed by #4289
Closed

Horizontal Rule adds empty line #1665

wmonecke opened this issue Jul 30, 2021 · 3 comments · Fixed by #4289
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@wmonecke
Copy link

wmonecke commented Jul 30, 2021

Description

When adding horizontal rule, you get a blank new line on top of the <hr/> tag.
I even used the following to make sure no <p/> would be rendered above with no avail.

const CustomHorizontalRule = HorizontalRule.extend({
  draggable: true,
  renderHTML({ HTMLAttributes }) {
    return ["hr", HTMLAttributes, 0]
  },
})
Screen.Recording.2021-07-30.at.23.30.14.mov

Question

In other words: Is it possible to delete certain nodes programmatically?
In my case finding the last empty <p/> and deleting it after inserting a <hr/>

Solution

I dont know if this is the right way to do it, but I am just listening every transaction and dipatching a prosemirror action to delete the node.


onTransaction(event) {
      const { transaction, editor } = event
      if (transaction.steps.length > 0) {
        const stepOfInterest = transaction.steps[0]
        const arrayOfNodes = stepOfInterest.slice.content.content
        const foundHrNode = arrayOfNodes.find(
          (el) => el.type.name === "horizontalRule"
        )

        if (foundHrNode) {
          const tr = editor.view.state.tr
          tr.delete(stepOfInterest.from - 1, stepOfInterest.to - 1)
          editor.view.dispatch(tr)
        }
      }
    },
@wmonecke wmonecke added Type: Bug The issue or pullrequest is related to a bug v2 labels Jul 30, 2021
@SF-Simon
Copy link

SF-Simon commented Aug 2, 2021

I think this is a personal demand, not the general public. Deleting the

is not an ideal way if someone wants to keep one more line blank on the horizontal line.

And why delete a

? Instead of all the blank lines?

@wmonecke
Copy link
Author

wmonecke commented Aug 2, 2021

@HeebeLee To me it feels more intuitive and in line with tip tap (unopinionated).

@cadars
Copy link
Contributor

cadars commented Sep 29, 2021

@philippkuehn Looks like this issue is still here…
To reproduce, go to https://tiptap.dev/examples/default and create an <hr>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants