[ruby/reline] Fix vi_to_column which was broken
(https://github.com/ruby/reline/pull/679) https://github.com/ruby/reline/commit/9e93ad52e7
This commit is contained in:
parent
07ff4aa19b
commit
43f4da3ebf
@ -540,10 +540,6 @@ class Reline::LineEditor
|
|||||||
new_lines.size - y
|
new_lines.size - y
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_row
|
|
||||||
wrapped_lines.flatten[wrapped_cursor_y]
|
|
||||||
end
|
|
||||||
|
|
||||||
def upper_space_height(wrapped_cursor_y)
|
def upper_space_height(wrapped_cursor_y)
|
||||||
wrapped_cursor_y - screen_scroll_top
|
wrapped_cursor_y - screen_scroll_top
|
||||||
end
|
end
|
||||||
@ -2483,18 +2479,11 @@ class Reline::LineEditor
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def vi_to_column(key, arg: 0)
|
private def vi_to_column(key, arg: 0)
|
||||||
current_row_width = calculate_width(current_row)
|
# Implementing behavior of vi, not Readline's vi-mode.
|
||||||
@byte_pointer, = current_line.grapheme_clusters.inject([0, 0]) { |total, gc|
|
@byte_pointer, = current_line.grapheme_clusters.inject([0, 0]) { |(total_byte_size, total_width), gc|
|
||||||
# total has [byte_size, cursor]
|
|
||||||
mbchar_width = Reline::Unicode.get_mbchar_width(gc)
|
mbchar_width = Reline::Unicode.get_mbchar_width(gc)
|
||||||
if (total.last + mbchar_width) >= arg
|
break [total_byte_size, total_width] if (total_width + mbchar_width) >= arg
|
||||||
break total
|
[total_byte_size + gc.bytesize, total_width + mbchar_width]
|
||||||
elsif (total.last + mbchar_width) >= current_row_width
|
|
||||||
break total
|
|
||||||
else
|
|
||||||
total = [total.first + gc.bytesize, total.last + mbchar_width]
|
|
||||||
total
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -711,6 +711,20 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
|
|||||||
assert_line_around_cursor('', ' abcde ABCDE ')
|
assert_line_around_cursor('', ' abcde ABCDE ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_vi_to_column
|
||||||
|
input_keys("a一二三\C-[0")
|
||||||
|
input_keys('1|')
|
||||||
|
assert_line_around_cursor('', 'a一二三')
|
||||||
|
input_keys('2|')
|
||||||
|
assert_line_around_cursor('a', '一二三')
|
||||||
|
input_keys('3|')
|
||||||
|
assert_line_around_cursor('a', '一二三')
|
||||||
|
input_keys('4|')
|
||||||
|
assert_line_around_cursor('a一', '二三')
|
||||||
|
input_keys('9|')
|
||||||
|
assert_line_around_cursor('a一二', '三')
|
||||||
|
end
|
||||||
|
|
||||||
def test_vi_delete_meta
|
def test_vi_delete_meta
|
||||||
input_keys("aaa bbb ccc ddd eee\C-[02w")
|
input_keys("aaa bbb ccc ddd eee\C-[02w")
|
||||||
assert_line_around_cursor('aaa bbb ', 'ccc ddd eee')
|
assert_line_around_cursor('aaa bbb ', 'ccc ddd eee')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user