ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.61k stars 336 forks source link

`joinTextblockBackward` doesn't work in a nested blockquote #1360

Closed ocavue closed 1 year ago

ocavue commented 1 year ago

I'm testing joinTextblockBackward. I found that it doesn't work as expected when inside a nested block.

Steps to reproduce:

  1. Add the following test case to this test suit: https://github.com/prosemirror/prosemirror-commands/blob/40d42d53a584c0ae31938f5915c39845b70346f4/test/test-commands.ts#L107
describe("joinTextblockBackward", () => {
  // This is the existing test case 
  it("can join if first block is wrapped", () =>
     apply(doc(blockquote(p("hi")), p("<a>there")), joinTextblockBackward, doc(blockquote(p("hi<a>there")))))

  // This is the new test case 
  it("can join if inside a nested block", () =>
     apply(doc(blockquote(blockquote(p("hi")), p("<a>there"))), joinTextblockBackward, doc(blockquote(blockquote(p("hi<a>there"))))))
})
  1. Run the test.

Expected behavior

Test should pass. These two test cases should have similar behavior, i.e. the gap between hi and there should be removed.

Actual behavior

Test failed. joinTextblockBackward did nothing, because of the if condition step.slice.size >= afterPos - beforePos at here.

marijnh commented 1 year ago

Attached patch should fix this.

ocavue commented 1 year ago

Thank you for the quick fix. The patch works well.