[前][次][番号順一覧][スレッド一覧]

ruby-changes:70458

From: aycabta <ko1@a...>
Date: Fri, 24 Dec 2021 00:52:07 +0900 (JST)
Subject: [ruby-changes:70458] 4bb65ee4fe (master): [ruby/reline] Character merging may increase the character width

https://git.ruby-lang.org/ruby.git/commit/?id=4bb65ee4fe

From 4bb65ee4fec933b87a269edc10e86720f8f24bbe Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
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(-)

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 053ec441a97..589f28caf15 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -2029,9 +2029,16 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2029
     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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]