[input-] fix editline() for characters having screen width > 1 #2662
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.
The input editor assumes characters have a screen width of 1. For double-width characters like
あ
, many alignment artifacts show up on screen. For example, edited values can extend 1 character past the edge of a visidata cell. Or after pressing=
, pasting several double-width characters into the input field, will cause ellipses…
to show up on the right side of the input. And scrolling horizontally within a cell, some characters are not visible when the cursor is on them.To demonstrate some of the issues, open a sample sheet with:
echo "12345678901234567890\nABCDEFGHIJ01-2--3---4--5--6--7--8-9" |vd -f tsv -
The header is single-width ASCII. The row is double-width letters and numbers, with single width dashes.
Shrink the cell with
z_
10
. Thene
and then pressRight
many times to see the problems. For example, after scrolling all the way right withEnd
, the last character,9
, cannot be seen.This PR fixes all known alignment issues in
InputWidget.editline()
for such characters. To handle the case where the screen does not have width to show a character with width > 1 at the start or end of the cell, extra…
characters will appear. For example, if a cell is 1 column too small to show…ABCD…
, the ellipses on the right side can be repeated in the column whereD
would otherwise start (becauseD
takes up 2 columns and can't fit into the one on screen):…ABC……
Or the ellipses on the left side can be repeated in the column whereA
would otherwise finish:……BCD…
(I am happy to finally be doing the
len()
vsdispwidth()
audit that I originally scheduled for summer 2023.)