-
-
Notifications
You must be signed in to change notification settings - Fork 290
[input-] fix editline() for characters having screen width > 1 #2662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
b92bacf
to
f70cb7c
Compare
I'm glad you're doing the dispwidth audit, @midichef. It definitely has been a long time coming. This particular code though is already pretty complicated, and I'm worried these improvements exceed the code budget here. Is this the essential complexity of accounting for wide characters when truncating a displayed string? I'm wondering if there's a single function like |
You're right, this PR is overly complicated. It also does not reproduce the existing desired behavior of the cursor for some corner cases. I've got a draft of a better version I'll submit soon. |
@midichef Would you like us to close this one? |
@anjakefala |
@midichef Oh, that's fine! I forgot about force-pushing. That keeps the history of the conversation. |
f70cb7c
to
7ca759a
Compare
Okay, I've force-pushed a new version that is much simpler than my previous attempt. It's also more correct: the original commit changed some cursor alignment behavior, but the new commit keeps the existing behavior. Some comments on my choices:
|
7ca759a
to
eee33d0
Compare
I added another commit cleaning up To expand on my note in There's probably a library that handles clipping Unicode strings more thoroughly. Maybe that's a feature offered by For this PR, I think the approach used for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whew! this has been quite a ride. This looks good to me by reading; @anjakefala can you do a quick perf pass with a large screen size compared to v3.1?
eee33d0
to
c81f745
Compare
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.)