Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Sep 11, 2023

Fixes #581
Left: before, Right: after
image

# Input for the above screenshot (no linebreak, 0-9 are fullwidth numbers)
'01234567890123456789-
01234567890123456789-
01234567890123456789-
01234567890123456789'.size

Fixes rendering bug of #491 but cursor position bug is not fixed. (Need to change all % @screen_size.last in line_editor.rb)

visual_lines.each do |line|
Reline::IOGate.move_cursor_column(0)
if line.nil?
if calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last
Copy link
Member Author

@tompng tompng Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visual_lines is calculated by Reline::Unicode.split_by_width

screen_width = 4
Reline::Unicode.split_by_width('helloworld', screen_width).first 
# => ["hell", nil, "owor", nil, "ld"]
irb(main):021> Reline::Unicode.split_by_width('Hello World!', screen_width).first 
# => ["Hell", nil, "o Wo", nil, "rld!", nil, ""]
Reline::Unicode.split_by_width('helloあwいoうrlえおd', screen_width).first 
#=> ["hell", nil, "oあw", nil, "いo", nil, "うrl", nil, "えお", nil, "d"]

Odd index value is always nil.
Normally, Even index value except last value satisfies Reline::Unicode.calculate_width(_1) == screen_width.
If there is a fullwidth character, text width might not equal to screen_width.

This condition is always true for halfwidth chars.
I think this condition is trying to check if visual_lines[index - 1] is the last element or not.
It's always non last element because visual_lines[index] is nil and visual_lines[index + 1] is the last element of visual_lines.
So this condition must be true for fullwidth chars too.

@tompng
Copy link
Member Author

tompng commented Dec 1, 2023

#595 will fix both disappearing and cursor position

@tompng tompng closed this Dec 1, 2023
@tompng tompng deleted the fix_fullwidth_long_line_disappear branch December 1, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long lines containing multibyte characters sometimes disappear

1 participant