summaryrefslogtreecommitdiff
path: root/lib/irb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-10-08 03:43:21 +0900
committergit <svn-admin@ruby-lang.org>2021-10-08 10:33:39 +0900
commit5c02df829665ea2063c674fba93d3025817718cf (patch)
tree9877013ddc36e4bcb8eb0772fa50aa220d8b9003 /lib/irb
parent36bf378363519f70ee7955fd86b6281224ce051a (diff)
[ruby/irb] Display doc dialog in gaps on narrow screen
https://github.com/ruby/irb/commit/4d7cefcaa4
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/input-method.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index d65c0308c6..f005ed7474 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -366,14 +366,35 @@ module IRB
end
return nil if doc.nil?
width = 40
+
+ x = cursor_pos_to_render.x + autocomplete_dialog.width
+ if x + width > screen_width
+ old_width = screen_width - (x + 0)
+ new_x = autocomplete_dialog.column - width
+ new_x = 0 if new_x < 0
+ new_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
+ if old_width.positive? and new_width.positive?
+ if old_width >= new_width
+ width = old_width
+ else
+ width = new_width
+ x = new_x
+ end
+ elsif old_width.positive? and new_width.negative?
+ width = old_width
+ elsif old_width.negative? and new_width.positive?
+ width = new_width
+ x = new_x
+ else # Both are negative width.
+ return nil
+ end
+ end
formatter = RDoc::Markup::ToAnsi.new
formatter.width = width
dialog.trap_key = alt_d
message = 'Press Alt+d to read the full document'
contents = [message] + doc.accept(formatter).split("\n")
- x = cursor_pos_to_render.x + autocomplete_dialog.width
- x = autocomplete_dialog.column - width if x + width >= screen_width
y = cursor_pos_to_render.y
DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
}