-
Notifications
You must be signed in to change notification settings - Fork 185
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
Fix inconsistent popup's bottom margins #1568
Conversation
ST can't margin-collapse margins of nested elements so elements with bottom-margin that were direct children of the .lsp_popup element would add an extra margin to the popup's bottom side. Fix by instead always appending a spacer element with top margin at the end of the popup contents. ST is able to margin-collapse margins of sibling elements so that should create a consistent margin, regardless of the content. Fixed by creating a helper functions for showing and updating popups that always add the spacer element. Those also have defaults for some common arguments so that we don't have to always pass them. One additional logic change, apart from adding the spacer element is that we default to max_height=800 instead of the default max-height=240. Resolves #1553
I see it not working in some cases so will have to investigate more. |
It's a slightly different case of the margin-collapsing ST bug that is still not working: <div class="lsp_popup">
<div>
<div class="highlight">
code block
</div>
</div>
<div class="lsp_popup--spacer"></div>
</div> The |
This issue was my biggest annoyance lately. Thanks for fixing it. :) Sure there are cases that this PR won't cover. But if fixed all the issues that I had experienced. I just found one case that is left.
- content += "<div>{}</div>".format(documentation)
+ content += documentation |
Yes, that was also where I saw the issue. Removing the wrapper div will improve things indeed but the problem will still pop up somewhere eventually, depending on the content. I'll apply your suggestion though and then we can decide if we want this or not. |
There is something in this sentence that makes me think that you are not happy with the implementation? But if I was more of a critique of the PR I would say: The only difference between Ideally I thought that we would only modify the css, and that the commit wouldn't be that long and easy revertable once ST fixes it, but this also works. |
Yeah, I'm not happy that it doesn't fix all cases. I think only the ST fix can really do this.
I think that's a nice thing about this change since:
I don't see a way to achieve a similar level of improvement with just using CSS. Your suggestions from the bug would apply in too many cases, removing the bottom margin from adjacent elements like code blocks or paragraphs. BTW. This workaround wouldn't break anything once ST fixes the margin-collapsing issue so we wouldn't need to rush to remove it. |
True
And true As for the "fixing all the possible case" while that is probably posslibe with more complex solutions. Those soultion would also not guarantee that we will still miss a few cases here and there. That said, I think that this solution is more than ok. |
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.
Some tiny nitpicks.
plugin/core/views.py
Outdated
def show_lsp_popup(view: sublime.View, contents: str, location: int = -1, md: bool = False, flags: int = 0, | ||
css: str = None, wrapper_class: str = None, | ||
max_width: int = 800, max_height: int = 800, | ||
on_navigate: Callable = None, on_hide: Callable = None) -> None: |
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.
The type is Optional[Callable]
for on_navigate
and on_hide
. I don't understand why mypy does not complain about this.
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.
It understands that it's optional because it has a default value (=None
) which "modifies" (or augments) the type.
I can change it if you prefer it more explicit (and longer). I forgot the style I'm supposed to use due to not touching the code in a while. ;)
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.
Alright let's see how it behaves :)
ST can't margin-collapse margins of nested elements so elements with
bottom-margin that were direct children of the .lsp_popup element would
add an extra margin to the popup's bottom side.
Fix by instead always appending a spacer element with top margin at the
end of the popup contents. ST is able to margin-collapse margins of
sibling elements so that should create a consistent margin, regardless
of the content.
Fixed by creating a helper functions for showing and updating popups
that always add the spacer element. Those also have defaults for some
common arguments so that we don't have to always pass them.
One additional logic change, apart from adding the spacer element is
that we default to max_height=800 instead of the default max-height=240.
Resolves #1553