Skip to content

Commit fbcd5f5

Browse files
committed
Character merging may increase the character width
Even if the number of graphemes doesn't change owing to character merging, the character width may increase.
1 parent 9f20b9e commit fbcd5f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/reline/line_editor.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,9 +2029,16 @@ def finish
20292029
last_byte_size = Reline::Unicode.get_prev_mbchar_size(@line, @byte_pointer)
20302030
@byte_pointer += bytesize
20312031
last_mbchar = @line.byteslice((@byte_pointer - bytesize - last_byte_size), last_byte_size)
2032-
if last_byte_size != 0 and (last_mbchar + str).grapheme_clusters.size == 1
2032+
combined_char = last_mbchar + str
2033+
if last_byte_size != 0 and combined_char.grapheme_clusters.size == 1
20332034
# combined char
2034-
width = 0
2035+
last_mbchar_width = Reline::Unicode.get_mbchar_width(last_mbchar)
2036+
combined_char_width = Reline::Unicode.get_mbchar_width(combined_char)
2037+
if combined_char_width > last_mbchar_width
2038+
width = combined_char_width - last_mbchar_width
2039+
else
2040+
width = 0
2041+
end
20352042
end
20362043
@cursor += width
20372044
@cursor_max += width

0 commit comments

Comments
 (0)