ruby-changes:58541
From: aycabta <ko1@a...>
Date: Sat, 2 Nov 2019 00:15:05 +0900 (JST)
Subject: [ruby-changes:58541] ea97933645 (master): Use prompt_list to calculate height by lines
https://git.ruby-lang.org/ruby.git/commit/?id=ea97933645 From ea97933645ad507c3015c7b2ca17035cf3008f96 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Fri, 1 Nov 2019 23:45:07 +0900 Subject: Use prompt_list to calculate height by lines diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 0e3544a..9ae7e6e 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -113,9 +113,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L113 if @line_index.zero? 0 else - @buffer_of_lines[0..(@line_index - 1)].inject(0) { |result, line| - result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list - } + calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list) end if @prompt_proc prompt = prompt_list[@line_index] @@ -188,6 +186,16 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L186 @is_multiline = false end + private def calculate_height_by_lines(lines, prompt_list) + result = 0 + lines.each_with_index { |line, i| + prompt = '' + prompt = prompt_list[i] if prompt_list and prompt_list[i] + result += calculate_height_by_width(calculate_width(prompt + line)) + } + result + end + private def insert_new_line(cursor_line, next_line) @line = cursor_line @buffer_of_lines.insert(@line_index + 1, String.new(next_line, encoding: @encoding)) @@ -346,9 +354,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L354 new_lines = whole_lines end prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt) - all_height = new_lines.inject(0) { |result, line| - result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list - } + all_height = calculate_height_by_lines(new_lines, prompt_list) diff = all_height - @highest_in_all move_cursor_down(@highest_in_all - @first_line_started_from - @started_from - 1) if diff > 0 @@ -388,9 +394,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L394 if @line_index.zero? 0 else - @buffer_of_lines[0..(@line_index - 1)].inject(0) { |result, line| - result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list - } + calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list) end if @prompt_proc prompt = prompt_list[@line_index] @@ -449,9 +453,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L453 if @line_index.zero? 0 else - new_buffer[0..(@line_index - 1)].inject(0) { |result, line| - result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list - } + calculate_height_by_lines(new_buffer[0..(@line_index - 1)], prompt_list) end @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 move_cursor_down(@first_line_started_from + @started_from) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/