ruby-changes:57450
From: aycabta <ko1@a...>
Date: Sun, 1 Sep 2019 12:35:08 +0900 (JST)
Subject: [ruby-changes:57450] aycabta: c5bb074fe7 (master): Re-calculate state variables of screen when screen size changes
https://git.ruby-lang.org/ruby.git/commit/?id=c5bb074fe7 From c5bb074fe731832b64143372986197c83201d2f3 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sun, 1 Sep 2019 11:02:14 +0900 Subject: Re-calculate state variables of screen when screen size changes diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index a1ec01d..597a391 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -71,7 +71,60 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L71 } Reline::IOGate.set_winch_handler do @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y + old_screen_size = @screen_size @screen_size = Reline::IOGate.get_screen_size + if old_screen_size.last < @screen_size.last # columns increase + @rerender_all = true + rerender + else + special_prompt = nil + if @vi_arg + prompt = "(arg: #{@vi_arg}) " + prompt_width = calculate_width(prompt) + special_prompt = prompt + elsif @searching_prompt + prompt = @searching_prompt + prompt_width = calculate_width(prompt) + special_prompt = prompt + else + prompt = @prompt + prompt_width = calculate_width(prompt, true) + end + back = 0 + new_buffer = whole_lines + prompt_list = nil + if @prompt_proc + prompt_list = @prompt_proc.(new_buffer) + prompt_list[@line_index] = special_prompt if special_prompt + prompt = prompt_list[@line_index] + prompt_width = calculate_width(prompt, true) + end + new_buffer.each_with_index do |line, index| + prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc + width = prompt_width + calculate_width(line) + height = calculate_height_by_width(width) + back += height + end + @highest_in_all = back + @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) + @first_line_started_from = + 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 + } + end + if @prompt_proc + prompt = prompt_list[@line_index] + prompt_width = calculate_width(prompt, true) + end + calculate_nearest_cursor + @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 + Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) + @rerender_all = true + end end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/