diff options
author | aycabta <aycabta@gmail.com> | 2021-12-24 00:16:31 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-12-24 00:51:48 +0900 |
commit | 4bb65ee4fec933b87a269edc10e86720f8f24bbe (patch) | |
tree | 99e8e8eda8b816628b80a0d3cbf7ef1ba1ba9916 /lib | |
parent | 726cc8122e5abb17a2af156e83ac88c1e4e9a42e (diff) | |
download | ruby-4bb65ee4fec933b87a269edc10e86720f8f24bbe.tar.gz |
[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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/line_editor.rb | 11 |
1 files changed, 9 insertions, 2 deletions
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 |