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

Prevent whitespace from rendering inside inlay hints #6312

Merged
merged 5 commits into from
Mar 16, 2023

Conversation

Zenthial
Copy link
Contributor

Addresses most of #6297.

Would like some advice on what should be done about tab rendering. Is it even needed to be addressed because I don't think the inlay hints would draw a tab?

@archseer
Copy link
Member

An empty file named origin was pushed

@@ -287,9 +287,11 @@ pub fn render_text<'t>(
style_span.0
};

let virt = grapheme.is_virtual().clone();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let virt = grapheme.is_virtual().clone();
let virt = grapheme.is_virtual();

Doesn't really make a difference but cloning a bool is kind of pointless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had this as a relic when I was working with &bool

@@ -405,14 +408,16 @@ impl<'a> TextRenderer<'a> {
}

let width = grapheme.width();
let space = if is_virtual { " " } else { &self.space };
let nbsp = if is_virtual { " " } else { &self.nbsp };
let grapheme = match grapheme {
Grapheme::Tab { width } => {
let grapheme_tab_width = char_to_byte_idx(&self.tab, width);
Copy link
Member

Choose a reason for hiding this comment

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

To properly render tabs you need to add a second field virtual_tab to which gets filled with white spaces in new instead of using whitespace chars.

Copy link
Contributor Author

@Zenthial Zenthial Mar 14, 2023

Choose a reason for hiding this comment

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

Gotcha. I believe its a bit verbose inside the Grapheme::Tab match, but it should now handle the tab rendering

Copy link
Member

Choose a reason for hiding this comment

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

Looks good now but I would prefer if you could move the if condition outside the match and handle it just like the other variables (so let tab = ..).

I thought it was quite clean how you did it for the other whitespace chars so it would be great if tab was the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, done.

pascalkuthe
pascalkuthe previously approved these changes Mar 15, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for taking this on 👍

@pascalkuthe pascalkuthe added E-easy Call for participation: Experience needed to fix: Easy / not much A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Mar 15, 2023
@pascalkuthe pascalkuthe added this to the next milestone Mar 15, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Mar 15, 2023

ah actually you need to fix the clippy lint before we can merge, it's just a smalmt Hong tough (chebk the ci run for details or run cargo clippy yourself)

@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Mar 15, 2023
@@ -313,6 +315,7 @@ pub struct TextRenderer<'a> {
pub nbsp: String,
pub space: String,
pub tab: String,
pub virtual_tab: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Must this be String? Can it be integer instead?

Copy link
Member

Choose a reason for hiding this comment

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

No we need the allocation to be able to hand out &str to it, just like the tab field. The tab width is not the interesting part here, we already know that from the grapheme.

@archseer archseer merged commit 2a27d1b into helix-editor:master Mar 16, 2023
sagnibak pushed a commit to sagnibak/helix that referenced this pull request Mar 21, 2023
* fix spaces and nbsps showing in inlay hints

* remove origin

* virtual tab + fix unneeded clone

* update virtual tab determining location

* fix clippy lint
icecreammatt pushed a commit to icecreammatt/helix that referenced this pull request Apr 19, 2023
* fix spaces and nbsps showing in inlay hints

* remove origin

* virtual tab + fix unneeded clone

* update virtual tab determining location

* fix clippy lint
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
* fix spaces and nbsps showing in inlay hints

* remove origin

* virtual tab + fix unneeded clone

* update virtual tab determining location

* fix clippy lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants