Reveal cursor on panel expand#7875
Conversation
|
@albertxing, i believe this should be done in |
|
@busykai That's a good idea, but I'm not sure if we would want to reveal the cursor when the editor resizes or even when the panel is resized, only when the panel is shown. |
|
@albertxing, that's fair, but i guess you could distinguish the types of resize events. it is much preferable to handle editor resize in a single place. there's a second param to the |
|
@busykai I see, do you think it would be alright if I added another |
|
@albertxing, currently that would be OK since we don't need to pass both refresh and scroll hints at the same time. a nicer solution would be pass an object as a refreshFlag, e.g. |
|
@busykai I just realized that we need to know the height of the expanded panel in order to determine whether or not to reveal the cursor. If we do this in EditorManager, we'll need to pass that information as an argument (which would be messy). Any ideas? |
|
The function already accept the new editor's height, which is |
|
I might be doing something wrong, but getting the current height and subtracting the new height gives me 0. I suspect this is because PanelManager:101 sets the editor's height before it triggers the event. |
|
no, i think you're right. this is how it was meant to function like this. i believe the cleanest way to fix this is to pass two heights (old and new) and hints as hash to the event (and to the handler). |
|
I can't find a clean place to fetch the old height of the editor - using Instead I decided to pass the height of the panel as a hint in refreshHint, and in EditorManager added the restriction that I'll commit the changes, please let me know what you think. |
|
Thanks! I will review it. Meanwhile, please merge with the latest master. |
|
@albertxing, thanks for fixing the merge. I've taken a look around and spotted this method: |
|
@busykai, I agree that it is quite heavy. Optimally it would be just a few lines of code - but then we'd have more code in other files (which might not be a bad thing). I tried the approach you mentioned by preserving the distance between the cursor and the bottom of the editor: It works well when the cursor would be hidden by the panel, but if would not be hidden then the sudden movement might be confusing - especially if we also center the cursor. I'm not sure if this is what you're looking for, let me know if there's anything that should change. Also ote that I'm passing a |
|
@albertxing, you have an extra character which breaks everything. Related to the implementation: 1. you can calculate if the position of the cursor is currently visible and not do anything if it is visible. 2. currently you're scrolling twice. you can actually calculate where the cursor would be before scrolling to it (once). |
|
Thanks, @busykai. I've also added the test for cursor visibility so it only scrolls when the cursor is hidden. |
|
@albertxing What about renaming |
|
@albertxing, thanks! now that it seems to be ok conceptually, i'll review the code over the weekend. and will think about the name, too. :) |
There was a problem hiding this comment.
Something like:
Determines if the cursor is currently visible and if not, scrolls the editor view port to make it visible. The distance between the cursor and the bottom is maintained, unless the cursor scrolls up higher than the editor center in which case line with the cursor will be centered.
There was a problem hiding this comment.
I just realized that maintaining distance to bottom is not strictly compatible with revealing the cursor, as if the cursor were initially hidden (before panel expand)then pushing the cursor up by the panel height will not reveal the cursor.
We'll have to decide whether we'd want to reveal the cursor in such a case by scrolling the minimal amount needed to show the cursor.
There was a problem hiding this comment.
Of course, we should never push it higher than the center of the resized editor (no matter what the distance to the bottom was).
Edit: didn't your concern right. if the cursor was not visible then we should probably do the same thing as it will scroll the text that was visible. i believe we don't need to actually reveal cursor in such cases.
There was a problem hiding this comment.
Sure, that makes sense. Would revealCursor be a suitable name if we were to do this?
There was a problem hiding this comment.
It actually can be used for other purposes as well, so Use only for panel expansion should be removed.
|
@albertxing, done with the first pass over the code. i'll also test some other cases (e.g. |
|
@busykai Thanks, I've looked over the comments and replied to some. I'll commit my changes (addressing everything except for the name change). |
There was a problem hiding this comment.
Seems like this comment could be more precise -- what does "maintaining the distance between the cursor and the bottom" mean given that the cursor is below the bottom at the time? Clearly we don't want to maintain that distance... It sounds like what we actually mean is something like "restoring the distance between the cursor and the bottom that existed before any bottom panels were shown"?
There was a problem hiding this comment.
I also wonder if trying to preserve the cursor's offset from the bottom edge is the right goal. It might be better to just scroll the minimum amount needed to keep the cursor in view (so it would be on the bottommost line visible, just above the panel) -- this minimizes the amount that the editor jumps, and minimizes how far away from its original onscreen location the cursor winds up. That actually seems better for the user (and might be simple to implement, too?).
|
@albertxing @busykai Added some review comments |
|
@peterflynn @busykai I've switched to the delta call from I also managed to get rid of the stray 3's and 4's somehow. Please let me know what you think. |
@peterflynn Simple fix for issue #3003, and (nearly) identical to closed and outdated pull request #3931.