-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
When scrolling the cursor into view, CM doesn't notice when it's wrapped in an additional scrollable container #1104
Comments
Try
|
This does fix the problem. Thanks However, |
Actually there is another problem with I updated the demo to put an additional element before codemirror: http://jsfiddle.net/vgZrs/4/ |
Yes, this is something that CodeMirror won't currently handle. It makes an effort to (vertically) scroll the cursor into view when the top-level document is scrolled away from it, but nothing beyond that. On WebKit, there's the You could consider listening to the |
Thanks for the heads up. I've actually simplified my design to just use a 100% height editor, but I suspect the container will eventually to be added back. When that happens and it's still not fixed in the CodeMirror, I would certainly take a stab at it. However, a quick search shows someone did try to implement a cross-browser scrollIntoViewIfNeeded. The implement has a few limits mentioned by the author. Not sure how much that might be of help. Also I did try to understand how the editor is scrolled into view by reading your blogs. One of them mentioned the hidden textarea, said browser scrolls it into view when there is activity in it. So I expect the content of the hidden textarea and the content of the editor are in sync, but probing the value of the hidden textarea shows it's only a few spaces chars (after the editor has been initialized, in the demo I provided earlier). Is the description in the blog still valid (in which case I must have missed something) or the model has actually changed? Thank you for sharing this great project and providing thorough documents. :) |
I found that implementation of The reason pressing Enter did not scroll the cursor into view, but typing regular text did, is precisely this hidden textarea. Whenever it gets input, it'll scroll into view. But CodeMirror handles Enter directly, so there the browser's behavior didn't kick in. |
I'm inspired to come up with a flawed solution: http://jsfiddle.net/vgZrs/6/ It But do you think I'm on the right track? If the hidden textarea could somehow be updated when Enter is pressed, the problem will be solved. |
A naive thought: why not let the textarea receive the actual Enter key, but does not insert the char into editor? Is it really hard to do that? |
I'm not sure that'd work (if it receives the key, it'll insert a newline, which then has to be somehow filtered out again), but it'd also not really solve the whole problem. Other keys, such as cursor movement, would still have the same problem. |
Just wanted to add my $0.02...it seems without this ability, auto-resized CodeMirror instances are of questionable usefulness, because at some point they will grow to big and need to be scrolled by their container. |
Thanks to @jmuharsky who has provided a very simple and clear reproduction of this problem: |
Did anyone solve this issue? |
Pardon my lengthy title. :)
This issue is better illustrated with an example: http://jsfiddle.net/vgZrs/
Try to insert a new line by pressing enter. The container is expected to scroll to bottom to display the cursor, but that only happens after you have actually typed some character.
This issue exists on all browser I tested: Chrome, Firefox, Opera (all in the latest dev version)
The text was updated successfully, but these errors were encountered: