summaryrefslogtreecommitdiff
path: root/lib/reline/unicode.rb
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2024-11-12 00:31:01 +0900
committergit <[email protected]>2024-11-11 15:31:04 +0000
commit25d17868de058cd857ec04496222b101be9a5429 (patch)
treec486139b4dbe9b4d08e59b8a59dc294fcff8e188 /lib/reline/unicode.rb
parent3ac5c053279c9a567fe1fa336840fd86f730c5e5 (diff)
[ruby/reline] Refactor perform_completon
(https://github.com/ruby/reline/pull/778) Flatten recursive method Remove CompletionState::COMPLETE https://github.com/ruby/reline/commit/aa5b278f3d
Diffstat (limited to 'lib/reline/unicode.rb')
-rw-r--r--lib/reline/unicode.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb
index 7bca22aeed..f8eb365069 100644
--- a/lib/reline/unicode.rb
+++ b/lib/reline/unicode.rb
@@ -633,6 +633,19 @@ class Reline::Unicode
byte_size
end
+ def self.common_prefix(list, ignore_case: false)
+ return '' if list.empty?
+
+ common_prefix_gcs = list.first.grapheme_clusters
+ list.each do |item|
+ gcs = item.grapheme_clusters
+ common_prefix_gcs = common_prefix_gcs.take_while.with_index do |gc, i|
+ ignore_case ? gc.casecmp?(gcs[i]) : gc == gcs[i]
+ end
+ end
+ common_prefix_gcs.join
+ end
+
def self.vi_first_print(line)
byte_size = 0
while (line.bytesize - 1) > byte_size