Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Unstyle empty list item on Enter key #769

Closed
wants to merge 5 commits into from
Closed

Unstyle empty list item on Enter key #769

wants to merge 5 commits into from

Conversation

ericbiewener
Copy link
Contributor

Summary

This appears to be standard functionality in text editors. If the list item has no text and the user pressed Enter, rather than creating a new list item, the current one should simply be removed. This is how it works in Google Docs, TextEdit, etc.

Test Plan

  1. Open the Rich Text editor example.
  2. Create a list item. Don't add any text to it.
  3. Press enter

The list item should be removed.

@rylev
Copy link

rylev commented Jan 25, 2017

@ericbiewener This change would be very useful. Any chance you can sign the CLA and we can get someone from Facebook to merge this?

@ericbiewener
Copy link
Contributor Author

@rylev I signed it a while ago. See the labels on the PR :)

@rylev
Copy link

rylev commented Jan 26, 2017

@ericbiewener sorry about that :-D Ok I guess we just need to sit back and wait for someone from Facebook to review this.

@flarnie
Copy link
Contributor

flarnie commented Oct 15, 2017

Very nice!

As with #762 I'd like to get a test for this, but that could be done as a follow-up. I can open an issue for the missing tests.

I'll see if we can get this merged. Great PRs! :D

@niveditc
Copy link
Contributor

niveditc commented Oct 7, 2018

@ericbiewener - looks like it will be useful to merge this in. I know that many Draft-based editors (including one that I wrote) are adding custom logic to handle this case, and it makes sense to me to add it natively in Draft itself.

Can you rebase onto master? Then I'll run a few sanity checks on production Facebook & can merge it in.

@ericbiewener
Copy link
Contributor Author

@niveditc all set. Updated tests as well.

Copy link
Contributor

@niveditc niveditc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just want to be a little more specific about the list item types we're matching like we do in other files :)

Couple of additional comments:

  • Looks like you added package.json in the commit with the test - can you exclude that?
  • I accidentally broke Travis CI on the base rev that you rebased on. Can you rebase again please? :)


if (!text) {
const blockType = blockToSplit.getType();
if (blockType && blockType.endsWith('-list-item')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be specific about the two list item types:
if (blockType === 'unordered-list-item' || blockType === 'ordered-list-item')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! All set.

@niveditc
Copy link
Contributor

It seems that package.json still shows up in this stack & didn't get deleted on d12d823

@ericbiewener
Copy link
Contributor Author

@niveditc Sorry, good to go for real this time :)

Copy link
Contributor

@niveditc niveditc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, looking good!

@niveditc
Copy link
Contributor

Next steps are:

  • I'll import this and run FB's test stack.
  • Do a few sanity checks in the browser.
  • Provided the steps above are successful I'll merge it in.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niveditc has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niveditc has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niveditc has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

jdecked pushed a commit to twitter-forks/draft-js that referenced this pull request Oct 9, 2019
Summary:
**Summary**

This appears to be standard functionality in text editors. If the list item has no text and the user pressed `Enter`, rather than creating a new list item, the current one should simply be removed. This is how it works in Google Docs, TextEdit, etc.

**Test Plan**

1. Open the Rich Text editor example.
2. Create a list item. Don't add any text to it.
3. Press enter

The list item should be removed.
Pull Request resolved: facebookarchive#769

Reviewed By: flarnie

Differential Revision: D10371552

Pulled By: flarnie

fbshipit-source-id: aa975e465c5cdbb1a8def62ba079545836211152
alicayan008 pushed a commit to alicayan008/draft-js that referenced this pull request Jul 4, 2023
Summary:
**Summary**

This appears to be standard functionality in text editors. If the list item has no text and the user pressed `Enter`, rather than creating a new list item, the current one should simply be removed. This is how it works in Google Docs, TextEdit, etc.

**Test Plan**

1. Open the Rich Text editor example.
2. Create a list item. Don't add any text to it.
3. Press enter

The list item should be removed.
Pull Request resolved: facebookarchive/draft-js#769

Reviewed By: flarnie

Differential Revision: D10371552

Pulled By: flarnie

fbshipit-source-id: aa975e465c5cdbb1a8def62ba079545836211152
aforismesen added a commit to aforismesen/draft-js that referenced this pull request Jul 12, 2024
Summary:
**Summary**

This appears to be standard functionality in text editors. If the list item has no text and the user pressed `Enter`, rather than creating a new list item, the current one should simply be removed. This is how it works in Google Docs, TextEdit, etc.

**Test Plan**

1. Open the Rich Text editor example.
2. Create a list item. Don't add any text to it.
3. Press enter

The list item should be removed.
Pull Request resolved: facebookarchive/draft-js#769

Reviewed By: flarnie

Differential Revision: D10371552

Pulled By: flarnie

fbshipit-source-id: aa975e465c5cdbb1a8def62ba079545836211152
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants