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

Ensure selection collapses if user tries to replace with matching text #1661

Closed

Conversation

existentialism
Copy link
Contributor

@existentialism existentialism commented Feb 20, 2018

Summary

This PR ensures that the selection is always collapsed for the cases where a user replaces the current selection with matching text.

I admittedly didn't really dig into the original issue when fixing the previous crash :)

Test Plan

Small repro:

  1. Type in "abc"
  2. Select "c" from right-to-left
  3. Type "c"
  4. Select "c" from left-to-right
  5. Type "c"

Thanks to @JLarky for bringing this to my intention!

Copy link
Contributor

@flarnie flarnie left a comment

Choose a reason for hiding this comment

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

Hooray!
dancing_taco

I'll get this merged today/tomorrowish, and then do a release now that we have this fix solidified.

@@ -29,13 +29,17 @@ const DEFAULT_SELECTION = {
isBackward: false,
};

//const collapsedSelection = new SelectionState(DEFAULT_SELECTION);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this~

@@ -125,5 +129,25 @@ test('editor selectionstate is updated if new text matches current selection', (
expect(editor.update).toHaveBeenCalledTimes(1);

const newEditorState = editor.update.mock.calls[0][0];
expect(newEditorState.getCurrentContent()).toMatchSnapshot();
expect(newEditorState.getSelection()).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

This narrows the focus of what this is testing - I think that's ok, just flagging to make sure it's intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the test was originally trying to vet SelectionState specifically, and actually serializing ContentState wasn't correct.

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.

@flarnie is landing 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.

@flarnie 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.

@flarnie 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.

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

@existentialism existentialism deleted the issue398-2 branch February 23, 2018 20:28
alicayan008 pushed a commit to alicayan008/draft-js that referenced this pull request Jul 4, 2023
Summary:
**Summary**

This PR ensures that the selection is always collapsed for the cases where a user replaces the current selection with matching text.

I admittedly didn't really dig into the original issue when fixing the previous crash :)

**Test Plan**

Small repro:

1. Type in "abc"
1. Select "c" from right-to-left
1. Type "c"
1. Select "c" from left-to-right
1. Type "c"

Thanks to JLarky for bringing this to my intention!
Closes facebookarchive/draft-js#1661

Differential Revision: D7055502

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

This PR ensures that the selection is always collapsed for the cases where a user replaces the current selection with matching text.

I admittedly didn't really dig into the original issue when fixing the previous crash :)

**Test Plan**

Small repro:

1. Type in "abc"
1. Select "c" from right-to-left
1. Type "c"
1. Select "c" from left-to-right
1. Type "c"

Thanks to JLarky for bringing this to my intention!
Closes facebookarchive/draft-js#1661

Differential Revision: D7055502

fbshipit-source-id: ee4cf80d292ee715e40c017e4c6bd18f806b0e24
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.

3 participants