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

Visible whitespace only for selections #2208

Closed

Conversation

tomKPZ
Copy link
Contributor

@tomKPZ tomKPZ commented Apr 21, 2022

No description provided.

@tomKPZ
Copy link
Contributor Author

tomKPZ commented Apr 21, 2022

This is my first foray into rust so the code may not be idomatic

@tomKPZ tomKPZ force-pushed the visibile-whitespace-selections branch from 2597768 to a5825b0 Compare April 21, 2022 03:53
@the-mikedavis the-mikedavis added the S-waiting-on-review Status: Awaiting review from a maintainer. label May 18, 2022
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Sorry for the delay on this. Admittedly it took me a while to figure out how this was working despite being familiar with these parts of the codebase 😅

helix-core/src/syntax.rs Outdated Show resolved Hide resolved
@tomKPZ tomKPZ force-pushed the visibile-whitespace-selections branch from a5825b0 to 9a8bea1 Compare August 7, 2022 00:53
@the-mikedavis
Copy link
Member

I'm not sure this makes sense or if it's too much of a micro optimization but we could not emit selection events when none of the WhitespaceRenderValues are for select. What do you think?

@tomKPZ
Copy link
Contributor Author

tomKPZ commented Aug 9, 2022

I'm not sure this makes sense or if it's too much of a micro optimization but we could not emit selection events when none of the WhitespaceRenderValues are for select. What do you think?

Sure, done in latest revision

Comment on lines 1147 to 1148
SelectionStart,
SelectionEnd,
Copy link
Member

Choose a reason for hiding this comment

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

Sorry it took a while! I wonder if we could avoid additional event types and instead just track this in the render loop. When HighlightStart(selection scope) is emitted we'd toggle a local bool to true, then false when it's popped off the scope stack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I hope I've understood your suggestion properly

Copy link
Member

Choose a reason for hiding this comment

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

I think archseer is saying that you can track this without changing the helix_core::syntax by looking up the scope for the highlight event and seeing if it's a selection scope:

HighlightEvent::HighlightStart(span) => {
    if theme
        .scopes()
        .get(span.0)
        .map(|scope| scope.starts_with("ui.selection"))
        .unwrap_default()
    {
        selecting = true;
    }
    spans.push(span);
}
// and for HighlightEnd, check that the popped scope starts with "ui.selection"

that snippet ☝️ isn't very performant though - we should calculate which indices in theme.scopes() correspond to selection highlights outside of the for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks for clarifying. I think I've done it in the latest revision

@the-mikedavis the-mikedavis removed the S-waiting-on-review Status: Awaiting review from a maintainer. label Aug 10, 2022
@tomKPZ tomKPZ requested a review from archseer August 10, 2022 19:57
@the-mikedavis
Copy link
Member

It looks like whitespace ends up not getting rendered for the cursor. For that we may need to include ui.cursor and ui.cursor.* (but there's also ui.cursorline so we can't use a starts-with check)

@archseer
Copy link
Member

I've done some simplifications, this way we can avoid comparing spans against the set of selection scopes in most cases. I'm also thinking if we want to remove that render closure for a regular function

@tomKPZ
Copy link
Contributor Author

tomKPZ commented Aug 17, 2022

Thanks for the commits @archseer !

I've added a fix for ui.cursor that @the-mikedavis found, and I've removed the inner render_whitespace closure, so no more dynamic dispatch is required for each whitespace char rendered.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Sep 13, 2022
@pascalkuthe
Copy link
Member

pascalkuthe commented Feb 1, 2023

With #5420 merged this PR will need to be ported to the new text rendering in ui/document.rs

@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 Feb 1, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Apr 13, 2024

clsoing this one as stale as the rendering code has been entirely replaced. Thank you for contributing

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

Configurable rendering of invisible characters like space, tab, and line feed
5 participants