From 4bb65ee4fec933b87a269edc10e86720f8f24bbe Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 24 Dec 2021 00:16:31 +0900 Subject: [ruby/reline] 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. https://github.com/ruby/reline/commit/fbcd5f56a7 --- lib/reline/line_editor.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 053ec441a9..589f28caf1 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -2029,9 +2029,16 @@ class Reline::LineEditor 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 -- cgit v1.2.3