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

Select and drag text in the editor is broken, can recreate this on draftjs.org #1454

Open
d-turner opened this issue Oct 25, 2017 · 12 comments

Comments

@d-turner
Copy link

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

What is the current behavior?
Select and drag text in the editor is broken, causes unpredictable behaviour.
Can recreate this on draftjs.org
Ubuntu:
Chromium Version 61.0.3163.100
Firefox Version 56.0
Windows:
Chrome

**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. You can use this jsfiddle to get started: **

Go to draftjs.org, enter a sentence into the editor, double click the first word to highlight it and drag it to another location in the editor.

The observed result is near different each time and is not what is expected, sometimes the dragged word remains in the original location and in the drop location, sometimes it is placed a few characters after the drop location.

It is tested at https://draftjs.org/

What is the expected behavior?

Move the selected text to the desired caret position.

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?

It is tested at https://draftjs.org/
Version 0.10.1
Version 0.10.4

@flarnie
Copy link
Contributor

flarnie commented Oct 25, 2017

Thanks for reporting this!

I just tried to reproduce it quickly in Chrome on MacOSX, and dragging text worked as expected for me.

dragging_text_ok_in_chrome

Can you provide more info about how to reproduce this? What browser and operating system are you using?

@d-turner
Copy link
Author

d-turner commented Oct 25, 2017

Thanks for the quick response, I have tried this on Windows Chrome and Ubuntu Chrome and Chromium
Below example is on Ubuntu Chrome Guest Session (No extensions or plugin):
Version 62.0.3202.62 (Official Build) (64-bit)

peek 2017-10-25 15-54

@flarnie
Copy link
Contributor

flarnie commented Oct 26, 2017

Aha - I was testing on Firefox. This is indeed easy to reproduce on Chrome, and what an awful bug! Thanks for reporting it!

I'd love to get a PR fixing it. This seems recent - I'm surprised I didn't catch it when manually testing in the past.

You mentioned being able to reproduce it in 0.10.1 - I wonder if it's a problem introduced by a Chrome version update rather than a change in Draft.

Either way, would be great to get a fix. If nobody picks this up I'll look into it when I have time.

@itssujan
Copy link
Contributor

I tried this on Mac Chrome and seems to be working fine.

@flarnie
Copy link
Contributor

flarnie commented Oct 27, 2017

Thanks for commenting @itsujan - I just tried again and was not able to reproduce it. I'm using Chrome 62.0.3202.62.

@itssujan
Copy link
Contributor

👍 Works all good for me too at Version 62.0.3202.75 🍏

@nickpassarella
Copy link

nickpassarella commented Nov 1, 2017

I'm actually able to reproduce on OSX Chrome 62.0.3202.75 if I follow the exact steps in @d-turner's clip.

drag_bug

I'm pretty sure this is in the code and not a browser issue.

https://github.com/facebook/draft-js/blob/aca0861e6dd10e921a75aabac9ec0206ae61010a/src/component/handlers/drag/DraftEditorDragHandler.js#L117

It seems dropSelection offsets are determined while the dragged/highlighted content is still in its original location. So if you are dragging and dropping within the same block away from the start, the dropSelection offset is going to be original focusOffset - anchorOffset characters further than you'd expect.

Notice in the above clip that when This (length: 4) is dropped, it ends up being placed 4 characters to the right of where you'd expect it to be. Everything works when dropping into another block, like @flarnie's clip, since the dropSelection's block isn't getting any content removed from it as part of the transaction.

I have a scratch fix working locally, so I can take this and open a PR soon when I can clean it up.

@mitermayer
Copy link
Contributor

@nickpassarella Awesome! Please feel free to submit a PR to this!

@jackyho112
Copy link
Contributor

This one has been sitting here for a while. I'm gonna give this a go if that's cool with everyone. Also, found this bug.

zw8fkclpw0

It only happens when you try to drag the selection onto the last line of the multiple selected lines. It may make sense to fix both bugs together.

@flarnie
Copy link
Contributor

flarnie commented Dec 6, 2017

Thanks @jackyho112 - it would be great to get a fix in for this.

ukrbublik added a commit to ukrbublik/draft-js-mod that referenced this issue Jan 4, 2018
ukrbublik added a commit to ukrbublik/draft-js-mod that referenced this issue Jan 6, 2018
ukrbublik added a commit to ukrbublik/draft-js-mod that referenced this issue Oct 7, 2018
ukrbublik added a commit to ukrbublik/draft-js-mod that referenced this issue Oct 9, 2018
facebook-github-bot pushed a commit that referenced this issue Oct 10, 2018
Summary:
**Summary**
Fixes issue #1383. Fixes problem which is: onDrop breaks onSelect/onChange events.
Fixes issue #1454 (partial). Fixes problem which is: after first internal drop dragged text will not be moved to target position, but copied.
The solution is to set `editor._internalDrag` to false not during onDragOver events, but after end of drag-n-drop.

**Test Plan**
Attached reproducable videos (on Chrome for Linux)
Issue #1383 before and after:
![1383-before](https://user-images.githubusercontent.com/3238637/46585340-68ec4100-ca78-11e8-9c2f-c98e7cb381ff.gif)
![1383-after](https://user-images.githubusercontent.com/3238637/46585344-6c7fc800-ca78-11e8-9c2e-fdac5594d1d0.gif)
Issue #1454 before and after:
![1454-before](https://user-images.githubusercontent.com/3238637/46585364-9e912a00-ca78-11e8-9c17-5dfcec5a2e16.gif)
![1454-after](https://user-images.githubusercontent.com/3238637/46585361-9a650c80-ca78-11e8-8b7f-dac6c6af4b23.gif)
Pull Request resolved: #1599

Differential Revision: D10236073

fbshipit-source-id: 3b7b816630f3b5b15931cb53782a1d5b9e9d5121
jdecked pushed a commit to twitter-forks/draft-js that referenced this issue Oct 9, 2019
Summary:
**Summary**
Fixes issue facebookarchive#1383. Fixes problem which is: onDrop breaks onSelect/onChange events.
Fixes issue facebookarchive#1454 (partial). Fixes problem which is: after first internal drop dragged text will not be moved to target position, but copied.
The solution is to set `editor._internalDrag` to false not during onDragOver events, but after end of drag-n-drop.

**Test Plan**
Attached reproducable videos (on Chrome for Linux)
Issue facebookarchive#1383 before and after:
![1383-before](https://user-images.githubusercontent.com/3238637/46585340-68ec4100-ca78-11e8-9c2f-c98e7cb381ff.gif)
![1383-after](https://user-images.githubusercontent.com/3238637/46585344-6c7fc800-ca78-11e8-9c2e-fdac5594d1d0.gif)
Issue facebookarchive#1454 before and after:
![1454-before](https://user-images.githubusercontent.com/3238637/46585364-9e912a00-ca78-11e8-9c17-5dfcec5a2e16.gif)
![1454-after](https://user-images.githubusercontent.com/3238637/46585361-9a650c80-ca78-11e8-8b7f-dac6c6af4b23.gif)
Pull Request resolved: facebookarchive#1599

Differential Revision: D10236073

fbshipit-source-id: 3b7b816630f3b5b15931cb53782a1d5b9e9d5121
jdecked pushed a commit to twitter-forks/draft-js that referenced this issue Oct 9, 2019
Summary:
**Summary**
Fixes issue facebookarchive#1383. Fixes problem which is: onDrop breaks onSelect/onChange events.
Fixes issue facebookarchive#1454 (partial). Fixes problem which is: after first internal drop dragged text will not be moved to target position, but copied.
The solution is to set `editor._internalDrag` to false not during onDragOver events, but after end of drag-n-drop.

**Test Plan**
Attached reproducable videos (on Chrome for Linux)
Issue facebookarchive#1383 before and after:
![1383-before](https://user-images.githubusercontent.com/3238637/46585340-68ec4100-ca78-11e8-9c2f-c98e7cb381ff.gif)
![1383-after](https://user-images.githubusercontent.com/3238637/46585344-6c7fc800-ca78-11e8-9c2e-fdac5594d1d0.gif)
Issue facebookarchive#1454 before and after:
![1454-before](https://user-images.githubusercontent.com/3238637/46585364-9e912a00-ca78-11e8-9c17-5dfcec5a2e16.gif)
![1454-after](https://user-images.githubusercontent.com/3238637/46585361-9a650c80-ca78-11e8-8b7f-dac6c6af4b23.gif)
Pull Request resolved: facebookarchive#1599

Differential Revision: D10236073

fbshipit-source-id: 3b7b816630f3b5b15931cb53782a1d5b9e9d5121
@hejtmii
Copy link

hejtmii commented Mar 30, 2020

Hi, what is the status of this issue?

I have tried it on 0.11.4 as well as on draftjs.org, and I can still see some problems. In particular when you drag the text forward on the same line, the target index does not subtract the length of the dragged text, placing it much further in the text than it should. When it lands after the end of the text, it even makes the editor content inconsistent.

In addition to that, we drag and drop custom blocks using external drag and drop functionality, and we face an issue that the editor sometimes sets its mode to drag but after drop (not currently sure about how to exactly reproduce it on a simple showcase) doesn't reset it back to the edit mode, leaving the editor in a state which completely stops responding to events.

Is there some way to completely disable drag and drop handling by the editor?

@tobi-or-not
Copy link

I am also trying to figure out the status of this issue. As far as I can see, where were pull requests addressing the problem but none of them was accepted. Can anyone help understand how to fix this bug?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants