I am trying to implement a functionality that will let me drag around decorated text within a Draft.js editor and have spent a couple of days worth of brain power on this problem.
The blue hightlights are chords in lyrics and my goal is to adjust their position within the text.
My strategy
- mark the text within the decorator
onClick
when the decorator is clicked - move the marked text around
I am aware that I am creating a race condition in Draft.js but I do not know how to solve the problem.
Code
I have a test set up which is available on Github.
https://github.com/tobi-or-not/draft-js-experiments
Scenario 1:
I click a button in the same component that displays the editor. This works perfectly. After the button is pressed, part of the text is marked
Scenario 2:
I click the decorator. After the click, the editor is back to it's initial state
There must be something I do not understand. Maybe there is a better way to implement this kind of drag-and-drop to begin with. Ideas and hints are much appreciated!