Skip to content

Commit

Permalink
Character merging may increase the character width
Browse files Browse the repository at this point in the history
Even if the number of graphemes doesn't change owing to character
merging, the character width may increase.
  • Loading branch information
aycabta committed Dec 23, 2021
1 parent 9f20b9e commit fbcd5f5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2029,9 +2029,16 @@ def finish
last_byte_size = Reline::Unicode.get_prev_mbchar_size(@line, @byte_pointer)
@byte_pointer += bytesize
last_mbchar = @line.byteslice((@byte_pointer - bytesize - last_byte_size), last_byte_size)
if last_byte_size != 0 and (last_mbchar + str).grapheme_clusters.size == 1
combined_char = last_mbchar + str
if last_byte_size != 0 and combined_char.grapheme_clusters.size == 1
# combined char
width = 0
last_mbchar_width = Reline::Unicode.get_mbchar_width(last_mbchar)
combined_char_width = Reline::Unicode.get_mbchar_width(combined_char)
if combined_char_width > last_mbchar_width
width = combined_char_width - last_mbchar_width
else
width = 0
end
end
@cursor += width
@cursor_max += width
Expand Down

0 comments on commit fbcd5f5

Please sign in to comment.