-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Mark individual incorrect characters #92
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pulled the repo and checked out the commit (c4a1980), however the compiled version does not highlight individual characters properly.
Namely: It will only higlight the first correct characters of a word green, not all correct characters.
This results in wirld
having w
green and irld
red, even though w rld
should be green and i
should be red.
let (typed, untyped) = | ||
self.words[self.current_word] | ||
.text | ||
.split_at(ceil_char_boundary( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in cargo throwing the warning:
warning: function `ceil_char_boundary` is never used
--> src/ui.rs:346:4
|
346 | fn ceil_char_boundary(string: &str, index: usize) -> usize {
| ^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the unused code.
Yep... Sorry my description was misleading. That was actually by design cuz sometimes one might mistype with extra characters, like If one really wants each individual character to be marked, probably #90 is the way to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the warning, still up for discussion if we want that behaviour.
What do other think?
Well another reasoning would be that it encourages you to go back and fix the mistyping, since that's what one would do in real-life typing. And the change helps you to see just how far back you should go (which is what I find useful anyway). Also it's less work :D |
@Sntx626 Just redid the thing, which should do exactly what you are asking now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Now it does exactly what the PR title says and works great.
Thanks for the contribution ^^
Hey there, author of #90 here. Just want to add a bit to the discussion. Seems like the behavior of the latest version of this PR exactly matches the one in #90. And it does this with less lines of code, which is nice. I guess in my PR I mixed this functionality with a small refactor. My motivation was that I believe UI code should be a very thin wrapper over representation. So I wanted to separate a bit the logic of checking which parts of the word are correct from the data types associated with Ratatui itself. I believe that doing this separation has 2 benefits:
The first point I think is important because, if we do want to evolve this crate to the vision of being more like monkey-type, then I think we need more tests to allow us to do more aggressive changes with confidence. Having said that, I am not married to the other PR at all. If @max-niederman prefers to merge this one since it is a smaller code change, I wouldn't mind. |
I think @glazari has a point, staying with the ratatui seperation would offer a better codebase in the future. Since both solve the same problem I'd say we should go for #90, since less code isn't always better code. I want to stress though that I'm happy with both implementations and think the final choice should be left to @max-niederman. |
As suggested in #75, when mistype happens, only mark
the wrong charactersstarting from the first wrong character to the end, instead of the entire word.A byproduct of marking individual characters is that it also fixes some issues mentioned in #77 (for example, accented letters like ä or é being counted as two characters).
Likely will conflict with #90. I'm submitting a PR since someone has requested it. Feel free to close if there are better solutions (or maybe use this as a temporary fix for v1, as the code change is not significant) .