Skip to content

Conversation

@Johann150
Copy link
Contributor

This should resolve #261.

Is this just okay like this, or should this be configurable?

@brendanzab
Copy link
Owner

Sorry for my slow review on this - need to figure out whether I'm happy with how we're iterating over the characters of a source line.

Comment on lines +247 to +253
let text_end = source
.char_indices()
.rev()
.take_while(|(_, c)| c.is_whitespace())
.last()
.map(|(index, _)| index)
.unwrap_or_else(|| source.len());
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 could also be rewritten using str::rfind, but because we have to find the first trailing non-whitespace character, we would have to find the char lengt of the character to adjust, which makes it not much clearer than the curren solution.

Suggested change
let text_end = source
.char_indices()
.rev()
.take_while(|(_, c)| c.is_whitespace())
.last()
.map(|(index, _)| index)
.unwrap_or_else(|| source.len());
let text_end = source
.rfind(|c| !char::is_whitespace(c))
.map(|index|
index + source[index..]
.chars()
.next()
.map_or(0, |c| c.len_utf8())
)
.unwrap_or_else(|| source.len());

@Johann150
Copy link
Contributor Author

@brendanzab any feedback on this?

@kaleidawave kaleidawave added the enhancement New feature or request label Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

There should be no source color highlighting if the label points to the whole line, or if the label is multiline

3 participants