plate icon indicating copy to clipboard operation
plate copied to clipboard

`deleteForward` swaps list items when subsequent list item contains mark

Open 12joan opened this issue 1 year ago • 3 comments

Description

See recording:

https://github.com/udecode/plate/assets/4272090/5a537414-5346-4b56-becd-ce28fc3009be

Steps

  1. Create a list with at least two bullet points
    • The first should be empty
    • The second should contain some marked and some un-marked text
    • See sandbox for an examlpe
  2. Place cursor on first bullet point
  3. Delete forward (fn+backspace)
  4. Plate swaps the first and second bullet points

Sandbox

https://codesandbox.io/s/sandpack-project-forked-n33oqb?file=/list/listValue.tsx

Environment

  • slate: 0.90.0
  • slate-react: 0.90.0
  • browser: cross-browser (Chrome + Firefox tested)

12joan avatar Jun 04 '23 13:06 12joan

Failing test case for deleteForward:

    const input = ((
      <editor>
        <hul>
          <hli>
            <hlic><htext /><cursor /></hlic>
          </hli>
          <hli>
            <hlic>
              <htext>one</htext>
              <htext bold>two</htext>
            </hlic>
          </hli>
        </hul>
      </editor>
    ) as any) as PlateEditor;

    const expected = ((
      <editor>
        <hul>
          <hli>
            <hlic>
              <htext><cursor />one</htext>
              <htext bold>two</htext>
            </hlic>
          </hli>
        </hul>
      </editor>
    ) as any) as PlateEditor;

    const editor = createPlateUIEditor({
      editor: input,
      plugins: [createListPlugin()],
    });

    editor.deleteForward('character');

    expect(editor.children).toEqual(expected.children);

12joan avatar Jun 04 '23 13:06 12joan

selectionIsInAListHandler seems to follow the same code path in both the working case (with no mark on the second line) and the non-working case (mixed text on the second line):

  1. !hasListChild(editor, listItem[0]) is true
  2. !liWithSiblings is false
  3. siblingListItem is truthy
  4. siblingList is truthy
  5. removeListItem(...) is falsey (Stop if the list item has no sublist)
  6. We return false

12joan avatar Jun 04 '23 13:06 12joan

@zbeyens Any guess as to what's causing this?

12joan avatar Jun 04 '23 13:06 12joan

/bounty $100

12joan avatar Jul 25 '23 20:07 12joan

~~💎 $100 bounty created by 12joan~~ ~~🙋 If you start working on this, comment /attempt #2420 to notify everyone~~ ~~👉 To claim this bounty, submit a pull request that includes the text /claim #2420 somewhere in its body~~ ~~📝 Before proceeding, please make sure you can receive payouts in your country~~ ~~💵 Payment arrives in your account 2-5 days after the bounty is rewarded~~ ~~💯 You keep 100% of the bounty award~~ ~~🙏 Thank you for contributing to udecode/plate!~~

Attempt Started (GMT+0) Solution
🟢 @Kagabe Jul 26, 2023, 12:14:53 AM WIP
🟢 @shashtag Jul 26, 2023, 8:26:24 PM WIP
🟢 @chandra1899 Aug 1, 2023, 2:26:34 AM WIP
🟢 @rishi-raj-jain Aug 11, 2023, 7:18:21 AM #2597
🟢 @nicktrn #2597

algora-pbc[bot] avatar Jul 25 '23 20:07 algora-pbc[bot]

/attempt #2420

ghost avatar Jul 26 '23 00:07 ghost

/attempt #2420

shashtag avatar Jul 26 '23 20:07 shashtag

Note: The user @Kagabe is already attempting to complete issue #2420 and claim the bounty. If you attempt to complete the same issue, there is a chance that @Kagabe will complete the issue first, and be awarded the bounty. We recommend discussing with @Kagabe and potentially collaborating on the same solution versus creating an alternate solution.

algora-pbc[bot] avatar Jul 26 '23 20:07 algora-pbc[bot]

/attempt #2420

chandra1899 avatar Aug 01 '23 02:08 chandra1899

@12joan I think this is taken care of already? I don't see this happening in production right now. PFA.

https://github.com/udecode/plate/assets/46300090/56767875-1021-4c59-8b9d-c897293243b8

rishi-raj-jain avatar Aug 11 '23 06:08 rishi-raj-jain

The default playground doesn't use the list plugin; it uses Indent List instead, which is unrelated.

image

Try it on https://platejs.org/docs/list

https://github.com/udecode/plate/assets/4272090/51adaba7-2491-41d4-bb43-bd84729dd27a

12joan avatar Aug 11 '23 06:08 12joan

Oh I see, I found another bug, PFA.

I don't think this is related to just mark? Anything after the empty line is being swapped which isn't just plain text, right?

https://github.com/udecode/plate/assets/46300090/bd6acea4-f654-4aa9-b763-9b50328b93c0

rishi-raj-jain avatar Aug 11 '23 06:08 rishi-raj-jain

If what you're referring to is "Parrots" being unindented, I don't think that's a bug.

I would start by adding the failing test for this issue and then figuring out why it happens for the mark case. There might be other bugs related to this, which will become apparent once you understand why this bug is happening.

12joan avatar Aug 11 '23 06:08 12joan

Running the tests locally is throwing the following:

image

Steps I've followed

  • clone
  • yarn install
  • yarn build
  • cd packages/list
  • yarn test

rishi-raj-jain avatar Aug 11 '23 07:08 rishi-raj-jain

/attempt #2420

Options

rishi-raj-jain avatar Aug 11 '23 07:08 rishi-raj-jain

Ah I see, the imports are using the package instead of the createList file. Importing that.

rishi-raj-jain avatar Aug 11 '23 07:08 rishi-raj-jain

💡 @rishi-raj-jain submitted a pull request that claims the bounty. You can visit your org dashboard to reward.

algora-pbc[bot] avatar Aug 11 '23 07:08 algora-pbc[bot]

I've just noticed this issue from 2021, which is probably related: https://github.com/udecode/plate/issues/1152. I can still reproduce it in latest Plate.

12joan avatar Aug 17 '23 15:08 12joan

@12joan Damn, This been going since nearly 2 years!

rishi-raj-jain avatar Aug 17 '23 18:08 rishi-raj-jain

💡 @nicktrn and @rishi-raj-jain submitted a pull request that claims the bounty. You can visit your org dashboard to reward.

algora-pbc[bot] avatar Sep 01 '23 21:09 algora-pbc[bot]

🎉🎈 @nicktrn has been awarded $50! 🎈🎊

algora-pbc[bot] avatar Sep 02 '23 13:09 algora-pbc[bot]

🎉🎈 @rishi-raj-jain has been awarded $50! 🎈🎊

algora-pbc[bot] avatar Sep 02 '23 13:09 algora-pbc[bot]

Thank you all, @12joan, @zbeyens, @nicktrn, and @zcesur! 🤍

rishi-raj-jain avatar Sep 02 '23 18:09 rishi-raj-jain