rhysd / tui-textarea

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

word wrap #54

Open pm100 opened 1 year ago

pm100 commented 1 year ago

@ryhsd I do not expect you to accept the PR. But I ask you to try it out, there is a new sample that shows it in action called wrap_dem. Just clone my repo , checkout branch wrap and run the sample wrap_dem. It starts in non wrap mode, you can toggle wrap on with ctrl-shift-r (wRap) or F1 and off with ctrl-shift-Z (Zero wrap) or F2

It required that tta knows at all times the relationship between the screen cursor and the data cursor, even in non-wordwrap they diverge - (non ascii chars etc), in wrap mode they are wildly different. Doing that enables a few other things. Importantly it sets the foundation for mouse support. Because mouse support requires that the mouse coordinates can be translated into data coordinates. This is simple with this change. The demo shows this, if you move the mouse over a character it tells you what that character is.

Note that this works with ascii, japanese, chinese, cyrillic, russion... I have tried with large bodies of text all mixed simultaneously. This web site will generate lorem text for you in any language https://www.lipsum.com/ - its what I used. All tests pass, tried on windows, linux and mac.

You are going to hate the code because its a largish change, but please try it out before dismissing it as a minor feature. Knowing precisely where any piece of text is on the screen is very useful for the caller (Imagine they want to do a spell check, or you want to add mouse driven text selection... these all become simple)

The merge is tricky and I dont want to go through it all if you are going to say no because its just too big. If you want I can add a readme / comment block that explains how it works.

rhysd commented 1 year ago

@pm100 Thank you for showing your implementation. Yes, I'll try this branch after working on #50 and releasing v0.4.1.

mcclure commented 3 days ago

Hello, is this still planned? Thank you!