Skip to content
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

Merged
merged 4 commits into from
Feb 5, 2021
Merged

Conversation

rchl
Copy link
Member

@rchl rchl commented Feb 3, 2021

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

rchl added 2 commits February 3, 2021 22:12
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
@rchl
Copy link
Member Author

rchl commented Feb 3, 2021

I see it not working in some cases so will have to investigate more.

@rchl
Copy link
Member Author

rchl commented Feb 3, 2021

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 .highlight has margin-bottom: 0.5rem and the extra div wrapper around it doesn't allow the margins to collapse.
The case that is fixed by this fix is when .highlight doesn't have a wrapper element.

@predragnikolic
Copy link
Member

predragnikolic commented Feb 3, 2021

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.

LSP/plugin/completion.py:43

- content += "<div>{}</div>".format(documentation)
+ content += documentation

before:
image

after
image

@rchl
Copy link
Member Author

rchl commented Feb 3, 2021

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.

@predragnikolic
Copy link
Member

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?
I mean if you are not, than maybe it is better to leave the bug aside and wait ST to fix it.
Although I am ok with all the changes here.

But if I was more of a critique of the PR I would say:
To me the only "downside" is that we will have show_lsp_popup which calls mdpopups.show_popup which calls view.show_popup. We will have a wrapper for a wrapper. Which is semi ok to me.

The only difference between show_lsp_popup and mdpopups.show_popup is that show_lsp_popup attaches an additional html tag at the bottom of the popup. Which is understandable.

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.

@rchl
Copy link
Member Author

rchl commented Feb 3, 2021

There is something in this sentence that makes me think that you are not happy with the implementation?

Yeah, I'm not happy that it doesn't fix all cases. I think only the ST fix can really do this.

To me the only "downside" is that we will have show_lsp_popup which calls mdpopups.show_popup which calls view.show_popup. We will have a wrapper for a wrapper. Which is semi ok to me.

I think that's a nice thing about this change since:

  • we can ensure more consistency with regards to max_width/max_height
  • less stuff to import when wanting to show or update a popup (no need to import mdpopups and .css)
  • fewer arguments to pass since we can rely on lsp-specific defaults
  • and of course the main point of this change - being able to add an extra spacer element from one place only.

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.

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.

@predragnikolic
Copy link
Member

I don't see a way to achieve a similar level of improvement with just using CSS

True

This workaround wouldn't break anything once ST fixes it

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.

Copy link
Member

@rwols rwols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tiny nitpicks.

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:
Copy link
Member

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.

Copy link
Member Author

@rchl rchl Feb 4, 2021

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. ;)

Copy link
Member

@rwols rwols left a 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 :)

@rwols rwols merged commit ea21ba7 into st4000-exploration Feb 5, 2021
@rwols rwols deleted the fix/popup-margin branch February 5, 2021 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the margin bottom from popups
3 participants