garybernhardt / selecta

A fuzzy text selector for files and anything else you need to select. Use it from vim, from the command line, or anywhere you can run a shell command.
MIT License
1.34k stars 81 forks source link

Combination of umlauts and tabs breaks selecta's UI #75

Closed untitaker closed 9 years ago

untitaker commented 9 years ago

The following command:

python -c '[print("ä\t" * 200) for i in range(20)]' | selecta

looks like this:

2015-02-01-133529_488x237_scrot

When I start typing, the cursor is still somewhere inbetween the suggestions:

2015-02-01-133550_349x171_scrot

Functionality-wise selecta works fine. This seems to occur only when the available suggestions exceed the screen's height.

This also occurs under zsh :P

untitaker commented 9 years ago

Note that this issue only occurs on rather narrow terminal widths, somewhat smaller than 80 chars or so.

untitaker commented 9 years ago

I've found a very simple algorithm for tab-expansion: http://stackoverflow.com/a/8900610

This would fix this issue and #73. It seems to output the same things as the expand command for ASCII input, umlauts, however, don't seem to be treated correctly (it's off by one character). So yeah, it counts bytes instead of graphemes. But I don't think it's important whether the UI does such incorrect things (which probably aren't even noticed), as long as it doesn't completely break!

garybernhardt commented 9 years ago

Fixed with the code you linked to. Tabs are the worst.

untitaker commented 9 years ago

On further thought, there are probably other graphemes whose column width differs from their amount of bytes in utf8.

garybernhardt commented 9 years ago

Selecta operates on graphemes (Ruby "chars"), so it does do the right thing. This example with Unicode snowmen should work just fine, for example:

python3 -c '[print("☃foo" * 200) for i in range(30)]' | selecta
rschmitt commented 9 years ago

Actually, @untitaker is right. Selecta does not place the cursor in the correct location when CJK characters are included in the query: screen shot 2015-02-23 at 10 30 33 pm By contrast, here is how Heatseeker renders the query: screen shot 2015-02-23 at 10 31 41 pm This was easy to get right in Heatseeker, because all I had to do was call this function from the Rust standard library. In the Ruby case, I'm not sure how you would fix this without taking a dependency on a gem.

garybernhardt commented 9 years ago

2a08d045af1abadd1cb1ebd8fdeabf7e5dbf30a7 should fix that. I took the easy way out: draw the query last, so the cursor naturally lands at the end of it. No need to compute the display length of the query. You could still construct a case where Selecta truncates strings in the candidate list more than it needs to, but that's very minor and I doubt that anyone will even notice.