-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Scroll to cursor if hidden by JSLint panel #3371
Conversation
Scroll to show cursor above panel if it would have been hidden.
Loosened scrolling threshold on upper end, to compensate for any height estimation errors.
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.
If 180 is the height of the panel, you should know that the panels are resizeables, so the height can be different from time to time. You might want to the the height of the panel with jQuery.
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.
Please use double quotes here, since that is part of the coding convention, and same with $('#jslint-results') below.
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.
Sure, wasn't aware of that. If there is a specific style guide for Brackets, where can I find it? (I've already figured out the 4-space indentation part)
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.
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.
Thanks!
Move metrics block to bottom for readability & aesthetics.
Align `var` declarations, change from `.CodeMirror` to `#editor-holder`, implement code portability.
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.
Now that the code is all together, you can move the scroll into view to line 212, change line 196 to if (editor && _gotoEnabled) and remove mustShow.
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.
Wow, you're like a human minifier.
Simplify code for readability & fewer variables; remove need for `mustShow`.
|
Great, this looks a lot better now, thanks for all the fast fixes :) |
|
@TomMalbran Thanks for all the good suggestions. If we were to generalize this for all bottom panels, which file would it be implemented to? The panels are just HTML elements that are created from a template. I was thinking (since all panels have class |
|
@TomMalbran I've tried adding the code to the https://gist.github.com/albertxing/8ef55ee58a72748f338a Do you think this is good enough to go into a commit? |
|
@albertxing @TomMalbran I'm concerned that the current code is JSLint-specific. We already have one other bottom panel in core (Find in Files results), and a number of extensions add bottom panels as well. So we need a generalized approach that all panels can share. Some combination of EditorManager & Resizer seems like the best place to do this -- panel clients should probably call into Resizer so we know when panels are shown/hidden, and perhaps EditorManager should own the actual scroll-into-view logic. We'd need to change JSLint & Find in Files to use Resizer's hide/show APIs instead of the generic jQuery calls, but we probably need to do that migration soon anyway (see my comment in #2015). Extensions that haven't made this switch yet shouldn't break, but they wouldn't automatically get the benefit of this fix until they do migrate. Note also that there are other situations where changes can make the cursor no longer visible. For example, window resize, panel resize, toggling word wrap on/off, closing one or more inline editors via Esc... we should think about which of those cases should have similar "auto scroll to visible" behavior. |
|
One more thought: we should add a small number of unit test to cover this too... perhaps in EditorManager-test. |
|
@peterflynn I've tested out an general implementation through EditorManager, and it seems to work for show/hide as well as panel/window resize. See https://gist.github.com/albertxing/8ef55ee58a72748f338a The only shortfall (if it even is one) is that resizing the windows without any panels open does not trigger the scrolling (it lets the cursor go out of view). I'm waiting for some code review before I make it a commit (it does change a pretty important part of Brackets). |
|
@peterflynn I've been thinking in the reviews about making it less JSLint specific, the only thing that is specific is the I was thinking of moving it to I don't think that most of the other situations (window resize, panel resize, toggling word wrap on/off) need this behavior since you are moving away from the coding to do this actions with the mouse. But we can leave that as a possibility if it gets requested. It would be worth adding it for closing inline editors since in this case you are using ESC to close the editor while coding, but I need to think how this 2 cases be refactored to work with the same code. Right now, it seems easier to add specific code for the editors problem (check if the cursor position is greater than 36 and less than the editor height before closing and check if the cursor position is less than 36 after). |
|
@peterflynn @TomMalbran Moving it to I just wanted to note that adding it to Putting the code in Resizer, however, does not trigger autoscrolling when the window is resized with the cursor still focused in the editor, whereas in EditorResize it does - so that's another difference to think about. I agree with @TomMalbran that this is not critical, and some may find it unnecessary/annoying. I don't see how this links too much to inline editors, since their behaviour doesn't in most scenarios push the cursor off the screen. |
|
Right, it isn't needed in If it would be necessary for the window resize, I wouldn't put it inside the It does push the cursor off the screen. Open an inline editor and scroll the editor, so that it is out of view in the top part. Place the cursor on the first visible line. Press ESC. The inline editor will disappear and the cursor got out of view. |
Generalize auto-scroll-to-cursor for all panels using Resizer. Implement Resizer show/hide in JSLint.
|
@TomMalbran @peterflynn I've generalized into Resizer for now, tell me if you want it in EditorManager as a separate function. Side note: @TomMalbran did you see what just happened there? There was a merge commit again, and I didn't even merge. This is ridiculously frustrating. 😖 |
src/utils/Resizer.js
Outdated
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.
As I mentioned in your gist, I don't think this is the best way to do it, since if you have for example the find in files panel open and the scroll behind it, so for the user is not in the view, and then the JSLint panel pops up, and that cursor not in view ends up in the view.
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.
Oh, didn't think of that (also didn't get notified for the gist).
|
Replying to the side note: I haven't seen any merge commits, but if there is a |
Use single element height instead of summed height of all panels to avoid scrolling when cursor is below the first panel when a second opens.
|
I've changed it to only use the single element (that's being called) height instead of the total height of all the panels. @TomMalbran I've grown to become afraid of them because they often mess up my own commits, mention committers who aren't involved as well as other issues that shouldn't be referenced (see my previous encounter in num#3248) |
|
@albertxing Yes that is ok. You don't really need to update your branch too much, it should only be needed when there are merge issue, or if there is something new that could alter the functionality of your code and you need to test, change your code. This is what makes branches great, you can have a branch stand for several days and still be mergeable, even after many commits where done to brackets. |
|
Still learning... 📖 Any ideas about a standalone function? Or is that something @peterflynn has to confirm? It seems pretty big to me. |
|
I'll wait on @peterflynn opinions about this. |
|
@albertxing Sorry for the slow reply. I've pushed up a branch with a proposal for cleaner APIs around panel management: pflynn/panel-management. It should provide a nicer place to attach this functionality: I think you can just put some code in This branch isn't entirely done yet, but if you'd like to try porting your fix over to use this code it'd be great to get your feedback. |
|
Oh, and by "not entirely done yet" I just mean there's some stuff I'm going to add to fix parts of #2015 before this is merged. But it should already be working just as well as the current Brackets master (let me know if you see any bugs!). |
|
@peterflynn Did you mean change the code here to use the changes implemented through |
|
@albertxing We just spotted this while reviewing old PRs. Sorry this fell through the cracks! It looks like PR #3931 is actually the more up-to-date patch, but it was auto-closed by GitHub when the branch is was based off of landed (in PR #3943)... so we lost track of it. (I hate that GitHub "feature," for the record :-P). Are you still interested in this? I think the next step would just be to reopen a new version of PR #3931 targeted at master. It looks like a good overall approach to me. Sorry again about the mixup & long delay... |
|
Also, I'm going to close this PR since it's the out of date one. I'll lave a note in bug #3003 pointing to the other PR as the most up to date implementation of a fix. |
|
Wow, I completely forgot about this already. I'll make a new pull request for issue #3003 soon. |
Scroll to show cursor above panel if it would have been hidden. Reference error #3003.