rhysd / tui-textarea

Simple yet powerful multi-line text editor widget for ratatui and tui-rs
https://crates.io/crates/tui-textarea
MIT License
347 stars 63 forks source link

selection is really hard to use for the non `input` caller #59

Open pm100 opened 9 months ago

pm100 commented 9 months ago

I have finally got the go ahead to put tui-textarea into gitui. I see that tta is now up to v0.4 and that now includes the keyboard based selection. I now see how you modified my original code.

The problem is that its very hard to use in the case where I am not using the keyboard dispatched via input. The new code there uses move_cursor_with_shift, this what I would have done except that it would have changed the existing API which I wanted to avoid. Which is why I came up with other stuff. Having a shift aware API makes it really easy (as your code shows), but that function is private.

Instead the non input using caller as to use start_selection and stop_selection. This means that I now have to reimplement the logic I already had in my original version that turns the selection on and off as the shift key is toggled, thats really tricky , even trickier outside TTA not having access to its insides (like is a selection already in progress?)

A simple solution would be to make the move_cursor_with_shift public, which would in fact make start_selection redundant (I think)

I think I can do the tricky thing for now but its not at all obvious what a caller needs to do (in the doc) and no samples show it either.

pm100 commented 9 months ago

@rhysd - good news, you have a new customer. tui-textarea finally merged into gitui, replacing their homegrown text input box. https://github.com/extrawurst/gitui/pull/2051

ty for you help over the last 6 months