New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CodeMirror scrolls current line to the bottom of the viewport on change #14
Comments
@meyer Hey thanks for opening this up as well as the awesome demo of exactly what's happening. Unfortunately, I am unable to reproduce this on my end. Are you using any other scripts that may be affecting this component? If you can spin up a quick isolated repo with this happening I'll gladly clone it down and get it fixed in a timely manner. Thanks! |
@scniro thanks for the quick reply. I wasn’t able to pin this issue down and it was affecting customers, so I took In toggling between |
@meyer cool just hit me up when you get it reproducing! It's looking like |
Same problem here. @meyer: Thanks for the great GIF I'm using redux, So I guess the problem happens, if you feed the string from |
@andi0b thanks for chiming in on this. However, that's the point of redux, right? If I remove that, everything totally beaks as far as setting the value. As soon as I can get a working repro I'll fix whatever issue is bothering you both 👍 |
@andi0b hey wanted to follow up, I thought this over again and I see what you're saying now. I did an experiment on my end where I bound class Editor extends React.Component {
constructor(props) {
super(props);
this.state = {
test: 'foo'
}
}
render() {
return (
<CodeMirror
value={this.state.test}
onChange={(editor, metadata, value) => {
this.setState({test: value}) // why feed this back to `value` here?
}}
/>
)
}
} So, I got it reproducing but I'd like to know more about what you are trying to do here. Codemirror has a value/state thats kept internally and the internal value is pumped out.
^totally true, and this is also causing |
Yeah this is definitely a bug. I am getting this as well except mine jumps around on the page on changes as you type. Honestly not sure how to show a demo of this as it is jumping above the textarea portion where you can't even see what you're typing, as you type. |
@justinwilson-apollidon what are you doing inside of |
@scniro So my usage is slightly different than others where I have an array of "sections" that allows the user to Add and Delete sections that include two fields, Title and HTML fields. Then this is stored through an API (besides the point or issue with this editor). That being said, I used this for the HTML field in particular and I have a this.state.sections.map() that iterates those two fields and component. onChange simply updates the object within sections: [], in state to save later when the form is submitted. I suppose my use case was slightly different than most as upon digging deeper into the source of your CodeMirror component, I noticed it may be something with refs. I'm not entirely sure honestly but I ended up switching over to Ace for now as it provides the functionality we require anyway. That being said, I'd be more than happy to help with this project in my personal spare time. |
@scniro: I'm not an experienced React developer, but as I understood it, it's a common pattern to keep a components content inside the state of the parent. And refresh the state if the component invokes changed events. This triggers unnecessary refreshes. But that happens all the time with React. |
@andi0b @justinwilson-apollidon @meyer thank you all so much for the collaboration. I'm happy to share that I believe I have a fix published up to 2.0.2. Basically, I was setting the value to the inner codemirror instance via
So, out with |
Closing for now - please reopen should this still be an issue or you can verify this is not fixed in the release referenced above, |
Hello! May you have forgotten to include this change at the newer versions? I'm experiencing exactly the same issue on Besides, there's also another bug I'm experiencing: When the first render happens, the scrollbar doesn't adjust to the height of the content. I made a hacky fix with this below, but maybe there's a better alternative? This is basically setting a state with a timeout so that it'll do re-render only the first time.
|
Here’s a GIF:
CodeMirror’s
value
comes from parent component state, and thehandleChange
method updates parent component state.The text was updated successfully, but these errors were encountered: