scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

Editor history cleared when state change from outside editor. #175

Closed BoostDmitry closed 4 years ago

BoostDmitry commented 4 years ago

Updating the code in the editor by updating the variable the code is stored in clears the editor history (no ctrl+z :cry: ). https://codesandbox.io/s/interesting-sky-6nvrv?fontsize=14&hidenavigation=1&theme=dark

scniro commented 4 years ago

@BoostDmitry I am a lot shorter on time these days as when I started this project. Codemirror & React APIs are moving to quickly for me to keep atop of for the day-to-day. I am looking for a co-maintainer of this project. Please contact me directly if you are interested. Thank you for understanding.

sukrut-gs commented 4 years ago

I am interested as a co-maintainer.

elsigh commented 4 years ago

@sukrut-gs - happy to help see this through if you have a PR or any ideas here? Offhand I wonder if this might help based on the description https://github.com/scniro/react-codemirror2/pull/146

fyi I have the same issue where I'm using the Controlled component and undo doesn't "work"

elsigh commented 4 years ago

I have a suspicion that what's missing is the performance of an "operation" in codemirror speak, ala

cm.operation(function () {
        cm.replaceRange(out, from, to);
    });
elsigh commented 4 years ago

yup, just tested this - in your paste handler if instead of calling setValue or whatnot you instead compute the values for cm.replaceRange and call that it works as intended (and automatically calls onBeforeChange for you thereby hitting your setValue call