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

improve layout of the prompt attachment #239514

Merged
merged 3 commits into from
Feb 3, 2025

Conversation

legomushroom
Copy link
Member

Improve the CSS styles of the prompt attachment:

image

@legomushroom legomushroom added this to the February 2025 milestone Feb 3, 2025
@legomushroom legomushroom self-assigned this Feb 3, 2025
Comment on lines 991 to 994
.chat-attached-context .chat-prompt-instructions-attachment:focus .monaco-button {
outline: none;
border-color: var(--vscode-focusBorder);
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise the border stays the same color while all others change to blue. That is the same logic we have for existing borders extended to this one.

Copy link
Member

Choose a reason for hiding this comment

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

I would have expected this to be handled by some general .monaco-button:focus rule? If you're copying this from elsewhere all good, but it looks like a potential code smell to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'd like it to be general component that I could reuse, but its not the case rn 🤔

Having a style that will allow this would in the monaco styles themself would be redundant and might feel like a code smell on its own - these styles are not for the monaco-buttom focus, but focus of the parent. Hence such styles would be something like *:focus .monaco-button {} which would not only have a negative performance impact, but also would require these styles to be reset for the components that don't need them 🤔

We also have many similar styles across the codebase (and many codesmells indeed!), including changes to the styles of its border (e.g., here) 🐰

@@ -987,6 +1003,11 @@ have to be updated for changes to the rules above, or to support more deeply nes
.chat-attached-context .chat-prompt-instructions-attachments .chat-prompt-instructions-attachment.warning.implicit {
border: 1px solid currentColor;
}
.chat-attached-context .chat-prompt-instructions-attachments .chat-prompt-instructions-attachment.implicit .monaco-button {
margin-top: -1.5px;
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need to get into decimals for margins?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not? The CSS spec allow that and it makes a difference in rendering at least on the high definition screens. These are the "device" pixels, not the "screen" ones, right?

The alternative fix would involve changing the hight of the entire attachment element which is much more disruptive change. I plan to do it at some point but that change needs more time and broader discussion with the team 🤷

Copy link
Member

Choose a reason for hiding this comment

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

These are "css pixels", not "device pixels. Meaning on low density displays this will probably shift the content 0.5px upwards and likely result in blurry horizontal b.orders

Copy link
Member Author

Choose a reason for hiding this comment

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

Right what I meant is - these are CSS pixels that are mapped to "device" pixels, that finally mapped to the "screen" pixels. Furthermore, all pixel values are represented as in ones, which adds a bit of indirection and can affect the final result.

So not sure how common the 1:1 density screens are still out there, but even if we assume there is an substantial amount of them, there are so many things that are out of our control that almost certainly will result in some blurred parts of the UI 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this margin-top change, I don't think we need it anymore.

Comment on lines 995 to 997
.chat-attached-context .chat-prompt-instructions-attachment .monaco-icon-label-container {
margin-top: -1px;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can this be solved a different way other than margin top? Is the thing above it too large?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can try to use a line-height(or even top) property instead but that might require an increased specificity of the CSS selector to be able to override the existing styles 😞

Copy link
Member

Choose a reason for hiding this comment

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

A negative margin top doesn't change the element's position in the flow of the page, meaning it's kind of like adding 1px padding to the bottom. We own everything here, so it might be more appropriate to change something else instead?

Why are these particular attachments special compared to other attachments such that they would be positioned 1px higher? Doesn't that mean they're going to be misaligned with regular attachments?

Copy link
Member Author

Choose a reason for hiding this comment

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

Margin top does not change how the flow model for elements that use them, but it does change position of the element on the page in all layout models, see https://codepen.io/sol0mka/pen/emOaZvB. The middle example is for the case when elements are "removed" from the normal flow, as you can see, there is no padding bottom, and the element position affect other elements 🤗

Why are these particular attachments special compared to other attachments such that they would be positioned 1px higher? Doesn't that mean they're going to be misaligned with regular attachments?

It is the attachment that I own 🤷 I'd like all our attachments to reuse the same component/styles, and the last time I've tried to touch someone else's code, I was stuck in PR feedback for a month 😞 So I decided to improve the style for at least the components that I have a control of ☺️

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw we also have a lot of mt: -1px and top: -1px across the code base 🙈 😄 (e.g., here)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this to using ems instead since that expresses the intent better - we want to have center based on the x-hight of the text. This is the simplest option we have, the alternatives are feel hacky and verbose 🤓

@legomushroom legomushroom requested a review from Tyriar February 3, 2025 21:59
@legomushroom legomushroom merged commit 4b9eb5a into main Feb 3, 2025
8 checks passed
@legomushroom legomushroom deleted the legomushroom/prompts/attachment-ui-improvement branch February 3, 2025 23:31
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.

3 participants