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: insert r_padding within final highlight #1368

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

danielwe
Copy link
Contributor

@danielwe danielwe commented Jan 17, 2025

When a component ends with a custom highlight, any r_padding should be added inside that highlight, not after, just like how l_padding is added inside a custom starting highlight. This PR takes care of that.

This is required to fully address folke/trouble.nvim#569 (see also folke/trouble.nvim#616 for the fix to trouble.nvim's own part in the issue).

Before:
Screen Shot 2025-01-16 at 16 53 11 PM

After:
Screen Shot 2025-01-16 at 17 18 20 PM

if self.status:reverse():find('%*%%.*#.*#%%') == 1 then
-- When component has changed the highlight at the end
-- we will add the padding before the highlight terminates
self.status = self.status:sub(1, -3) .. string.rep(' ', r_padding) .. self.status:sub(-2, -1)
Copy link
Member

Choose a reason for hiding this comment

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

Explain this line please. Why are you removing only last 2 chars and not the HL group mapping %#group_name# ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line inserts padding at the end of the <text> part of a string of the form %#Group#<text>%*, so the only characters to hold out are the last two characters %*.

@shadmansaleh
Copy link
Member

What's the point of having a HL marker at end of a component anyway? it'll get reset for the next component either way. If it's because the source you're taking data from already has HL markers then you can just remove the HL marker in user config side with fmt option. that'd work as expected.

@danielwe
Copy link
Contributor Author

danielwe commented Mar 13, 2025

There isn't a separate HL marker at the end, it's just that if a component is wrapped in a HL marker, %#Group#<text>%*, and I want to add padding, I should add the padding inside the marker such that it becomes part of the <text> component. Currently, this is done for left padding but not right padding---instead, right padding is added outside the marker after the final %*. With this PR, left padding and right padding are handled symmetrically.

@danielwe
Copy link
Contributor Author

See the screenshots in the OP: this PR addresses the miscolored space after view:wait

@shadmansaleh shadmansaleh merged commit b8b60c7 into nvim-lualine:master Mar 15, 2025
5 checks passed
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.

2 participants