Draft-js: Edge case - Paste doesn't remove current selection before mouseup

Created on 31 Jan 2017  路  4Comments  路  Source: facebook/draft-js

Do you want to request a feature or report a bug?
Bug.

What is the current behavior?
Editor does not remove selection when pasting unless mouseup has fired (it seems that a selection isn't registered until mouseup). I use a trackpad with 3 finger drag, which has a 300-ish millisecond delay after lifting. If I paste text in that window, the following behavior occurs:

draft-js

Basically, the repro steps are:

  1. Click and drag a selection
  2. Press cmd-P before mouseup

What is the expected behavior?
Paste removes currently selected text (potentially not possible). Perhaps it could disallow pasting before mouseup?

Honestly, even OS X gets this wrong. Try the same steps on the location bar.

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
DraftJS: 0.10.0
Browser: Chrome 56
OS: Mac OS X 10.12.2

bug help wanted

All 4 comments

Thanks for recording this behavior and describing it so well! It looks like this is a bug. I don't know how often it will come up as an issue for people, but it's true that it's not the expected behavior and would be nice to fix.

After playing with OS X paste behavior, this seems to be how it handles the mouseup interaction:

  • have some text "foo" in the the clipboard
  • select some text using the mouse: "bar" (bold indicating selection)
  • hit CMD+V to paste, without release mouse button
  • pasted text should not be inserted yet -- text is not replaced with pasted text until mouseup

    • therefore, if mouseup happens with the entirety of "bar" selected, it will be replaced with "foo"

    • however, if mouse selection is moved to "bar" before mouseup, it will result in "bafoo"

Would this be desirable for draft.js? I think this makes sense. Since selection doesn't change until mouseup, it seems logical that text cannot be pasted until _after_ mouseup.

If this is not possible, I think simply preventing paste before mouseup would be fine.

Yep, your proposal sounds reasonable.

This proposal to change React's onSelect event to use the native selectionchange api looks like it might resolve this issue.

https://github.com/facebook/react/issues/5785
https://github.com/facebook/react/pull/10746

Was this page helpful?
0 / 5 - 0 ratings