-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
This works good in most cases. I see that you don't do anything when a range is selected and cursor is inside of an inline editor. I think that's OK. The most problematic case is when the font-size is changed. It seems to work in the first couple hundred lines of a file, so use a really big file (such as brackets/src/thirdparty/CodeMirror2/lib/codemirror.js) and go near the end. I also tried an HTML file with an inline editor. it works perfectly with inline editor near top and scrolling down. Very nice! But there's a quirk with inline editor near bottom and scrolling up -- after cursor jumps over inline editor, it moves the next few lines (roughly about the height of the inline editor). |
{ | ||
"key": "Ctrl-Up", | ||
"displayKey": "Ctrl-\u2191", | ||
"platform": "win" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When specifying different shortcuts across platforms, specify whatever you want for platform:mac, but do not specify a platform on the other shortcut key so that it gets picked up by all other platforms (e.g. win, linux, etc.)
Done with initial review. |
@redmunds Thanks for the review!
|
textHeight = editor.getTextHeight(), | ||
cursorPos = editor.getCursorPos(), | ||
hasSelecction = editor.hasSelection(), | ||
paddingTop = editor._getLineSpaceElement().offsetTop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that Editor should have a new public method getPaddingTop
that would return editor._getLineSpaceElement().offsetTop
, and replaced _getLineSpaceElement
. Checking through the code, the only other place where _getLineSpaceElement()
is used is inside Editor to check the offsetTop, just like I did. Currently _getLineSpaceElement()
is not public because is really specific to code mirror, but replacing it for getPaddingTop
would make it less specific and could be changed to any other value if needed, even 0 if the padding would be removed at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding getPaddingTop
sounds like a good idea. What about the bottom and sides? Maybe a getPadding
method that returns an object with top
, right
, bottom
, and left
settings.
Here's my recipe and results for the different font-size case:
Results: works as expected
Results:
Results:
Results: Note: I see very similar results if I reduce font-size instead of increasing it. |
I can see now what you mean. I could even saw that error with the default font size near almost the end of It seems that CodeMirror makes every line not rendered have always a height of 15px, so when increasing the font-size, the top and height aren't calculated exactly. If you check the DOM and look for the parent of You can really see this being wrong done by increasing the font a lot (10 times do the job) in a medium size file like I also saw that doing Page Up after increasing the font a bit and using Ctrl+Down didn't showed the cursor on the visible lines. Sometimes it get fixed after using Page Down, but it can get broken again doing several fast Page Up, and I think is for the same reason. So the solution for now was to do the calculations based on the rendered lines, by removing the top position to the scroll top and then adding the first rendered line to the result. But it could be solved later in CodeMirror and go back to the previews commit. On |
On Mac 10.8, This looks great in the font-size increased case -- the page scrolls and cursor stays in view perfectly. The font-size decreased case also looks great on line scroll down. But, when I decrease the font-size and try to line scroll up the page doesn't scroll at all -- it doesn't see to matter where the cursor is or if anything is selected. On Windows 7, the cursor is never moved to keep it in the view (i.e. always stays on same line) even with default font-size. |
The line snapping was off by one line and paddingTop only fixed it for higher text sizes. I couldn't reproduce the Win7 bug (maybe because it doesn't happen in WinXP?), but I found and fixed a similar bug that didn't set the cursor into view when it was above the visible area and moving up or was below the visible area and moving down. |
The Windows 7 problem was a user error -- I forgot to uninstall my line scroll extension before testing your line scroll code :) This looks great. Merging. |
Great. Thanks. Should I add an issue for the scrolling, line height rendering problem? |
It would be good to log somewhere. I also notice that the cursor doesn't stay in the same position when you use PageUp/Down with non-default font-size. |
Will do, and one for getPadding/getPaddingTop too. |
Here we go again, but this time it should work. This implements scroll line up/down as mentioned in #2343 and should work with inline editors too.