-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Cursor position jumps after resize and when using line wrapping #1787
Comments
Are you seeing it stuck in the wrong place, or only briefly flickering at a wrong position and then being fixed again? (I only see the latter when I try to reproduce this.) |
@marijnh I actually see both behaviors. |
Despite what you wrote in adobe/brackets#4564, I am still not able to reproduce this. |
Oh, my mistake. I thought that's what you meant in your prior comment. |
Okay, let me elaborate. I see the jumping during resize. This is intentional. If the correct position is recomputed for every resize event, size dragging becomes terribly slow. So it delays a bit and only does the work every 200 ms. I actually believe this change was in response to a problem in Brackets, but I can't find the issue/thread for it right now. |
@marijnh |
Updated Chrome on my MacBook to 29, and really tried to follow your instructions to the letter, but I am still not seeing this happen. |
@marijnh Thanks for trying. I'll try to describe it on my own words and see you can reproduce it on your end.
|
I can reproduce this on Ubuntu 13.04, Firefox 23. I only have the outline resize when resizing windows (so size/page doesn't update until I let go of the edge). To reproduce, I just dragged the bottom edge of the window up a few pixels at a time until the cursor appears on the wrong line. When I do this, Line 6 wraps for a split second, the following lines move down, and the cursor remains in the same spot (previous line). Then, Line 6 unwraps, the following lines move back up, and the cursor updates to where it was when Line 6 was wrapped. Calling So, seems to me this is a race condition with the visual placement of the cursor div and the visual updating of the editor. Something like:
There should be a step between 4 and 5 that recalculates the scrollbar position before it's displayed, or a step 6 in which the cursor Original positionShows for split second (after resizing)Final position |
I've finally managed to reproduce this using Firefox (still no luck with Chrome). Investigating. |
Could you test whether the attached patch helps? |
Yes, the patch indeed fixes the issue. Thanks. |
Wondeful. |
@RaymondLim I actually was able to reproduced it still in my example http://jasonsanjose.github.io/uploads/word-wrap-bug.html with the same frequency as before. |
As was I. |
Yeah, you both are correct. I still can reproduce it with Jason's page in Chrome and Safari browser on Mac. The one case that it fixes is only in Brackets when resizing from the bottom edge. |
Try again with attached patch. I had isolated the problem in a test case that used |
Works for me! |
Thanks @marijnh. The new patch fixes the issue both in browsers and in Brackets. But it can also cause Brackets to hang. The hang seems to be caused by the infinite loop due to this condition check Update: Below is the call stack that I got from running unit test in Brackets.
|
The problem is almost certainly the
|
Yes, no longer hang but slow as you said. Below is two separate sections of console output. starting updateDisplay loop codemirror.js:413 and can continue up to a very large number width changed from 13626 to 13953 -- doing a hard re-measure codemirror.js:422 |
Well, there's certainly something unexpected going on there -- there's no way redrawing or remeasuring the code should cause the width to increase on every iteration. And why does it start so small? For me, when wrapping is turned on, I see only two widths -- the one where the vertical scrollbar is there, and the one where it's not. Can you inspect the actual DOM and see if the thing it contains during these tests is an actual sane editor? Can you see what is determining the width of the scroller element and how it could be constantly changing? |
It looks like we always start out with an empty editor window and show the gutter (line numbers) by default. If I set lineNumbers to false, then I don't see the width of scroller element constantly changing. Below is what I see in the console with lineNumbers default to false. starting updateDisplay loop codemirror.js:413 |
Still, no matter what the gutter is doing, with the default css, the scroll element's width should be fixed, so its |
It looks like the problem was that our unit tests create a mock container for the editor, and that mock container is absolutely positioned with no explicit width, so it's 0-width by default. This didn't cause a problem before, but I can imagine that it would cause issues after this change, since the editor itself will be the one that's determining the width of its container, so I can imagine how it could get into some kind of feedback loop (though I didn't dig into it to figure out exactly where the loop was causing form). I was able to work around this just by setting an explicit width on the mock container in our unit tests, since that's more realistic anyway. I don't know whether this is something that actually needs to be fixed in CM; this use case certainly isn't likely in normal real-world usage, but perhaps it's possible for someone to have a 0-width or small-width container in some edge case (e.g. at the start of an animation?), and it would be bad for CM to hang in that case. (I didn't actually create a test case with vanilla CodeMirror to see if that would trigger the same hang, though.) |
BTW, I didn't verify the original issue was fixed since I haven't been involved in the details--I'll put up a pull request in Brackets and have @RaymondLim verify that we're all set and can close this CM issue. |
Verify that the original issue (with Quick Docs or Quick Edit in Brackets) is also fixed with the latest update to CodeMirror. |
I've added a check to prevent problems in (more or less nonsensical) cases like this. Closing. |
Seems fine, thanks. |
Possible duplicate of #1642
Demo: http://jasonsanjose.github.io/uploads/word-wrap-bug.html.
Highlights
height: 100%
on bodyrefresh
and relying on the built-in window resize handlingSteps to reproduce:
Reproduced on Chrome 29 and Canary 31.
The text was updated successfully, but these errors were encountered: