Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My attempt at #87 .
This adds new public functions to TextArea:
This works, I'm actually already using it in a working program (while prototyping this lives in that repo as
cargo run --example vim
). However, there are two high-level issues:I need feedback as to whether you like this API or whether you'd be more likely to accept a different one. The "priority" in particular is really iffy. I (see highlight.rs:26) changed the existing priorities to 10, 20, 30, so there's lots of space between them, but that seems… I mean, it works, but it might be awkward if you add more builtins later and have to populate the priorities in between.
This code makes it really easy to create "overlapping regions". Textarea currently fails on this because it treats "end" like a stack. I don't believe this is a problem with this PR but a problem with the underlying code, as I think(?) I can recreate it by creating a search and a highlight at the same time (see my note in Feature request: Set style on range #87).
But look what happens when you try to use this patch:
Screencast.from.2024-12-08.20-17-29.webm
This program (the "ami" prototype I linked above) lets you input a song in a little music "programming language". If there is anything it doesn't recognize (basically anything other than a number) it highlights the first bad character in red. To test ranges, I changed the code so instead of highlighting one character it highlights the entire row after the highlighted character. There are two bad things I see here: One, the final character of the line is blue, and I don't know why; two, when the cursor starts overlapping (underlapping, the cursor priority is 30 and the error priority is 35) everything freaks out.
Minor issues: I haven't written tests yet, but if you tell me an external API you're happy with, I can do that; there is an outstanding clippy, an IMO spurious one (there's an eight-argument function and it thinks 7 should be the limit), I could refactor that but again want to know what final external API I'm targeting.