summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/reline.rb5
-rw-r--r--lib/reline/line_editor.rb18
-rwxr-xr-xtest/reline/yamatanooroti/multiline_repl14
3 files changed, 19 insertions, 18 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index b331421012..9746b35ac5 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -37,7 +37,7 @@ module Reline
alias_method :==, :match?
end
CursorPos = Struct.new(:x, :y)
- DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, :scrollbar, keyword_init: true)
+ DialogRenderInfo = Struct.new(:pos, :contents, :bg_color, :width, :height, :scrollbar, keyword_init: true)
class Core
ATTR_READER_NAMES = %i(
@@ -241,7 +241,8 @@ module Reline
context.clear
context.push(cursor_pos_to_render, result, pointer, dialog)
end
- DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, scrollbar: true, height: 15)
+ dialog.pointer = pointer
+ DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, scrollbar: true, height: 15)
}
Reline::DEFAULT_DIALOG_CONTEXT = Array.new
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index b2f7728a42..da8787af49 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -560,7 +560,7 @@ class Reline::LineEditor
class Dialog
attr_reader :name, :contents, :width
- attr_accessor :scroll_top, :scrollbar_pos, :column, :vertical_offset, :lines_backup, :trap_key
+ attr_accessor :scroll_top, :scrollbar_pos, :pointer, :column, :vertical_offset, :lines_backup, :trap_key
def initialize(name, config, proc_scope)
@name = name
@@ -643,7 +643,7 @@ class Reline::LineEditor
end
old_dialog = dialog.clone
dialog.contents = dialog_render_info.contents
- pointer = dialog_render_info.pointer
+ pointer = dialog.pointer
if dialog_render_info.width
dialog.width = dialog_render_info.width
else
@@ -652,15 +652,15 @@ class Reline::LineEditor
height = dialog_render_info.height || DIALOG_HEIGHT
height = dialog.contents.size if dialog.contents.size < height
if dialog.contents.size > height
- if dialog_render_info.pointer
- if dialog_render_info.pointer < 0
+ if dialog.pointer
+ if dialog.pointer < 0
dialog.scroll_top = 0
- elsif (dialog_render_info.pointer - dialog.scroll_top) >= (height - 1)
- dialog.scroll_top = dialog_render_info.pointer - (height - 1)
- elsif (dialog_render_info.pointer - dialog.scroll_top) < 0
- dialog.scroll_top = dialog_render_info.pointer
+ elsif (dialog.pointer - dialog.scroll_top) >= (height - 1)
+ dialog.scroll_top = dialog.pointer - (height - 1)
+ elsif (dialog.pointer - dialog.scroll_top) < 0
+ dialog.scroll_top = dialog.pointer
end
- pointer = dialog_render_info.pointer - dialog.scroll_top
+ pointer = dialog.pointer - dialog.scroll_top
end
dialog.contents = dialog.contents[dialog.scroll_top, height]
end
diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl
index e8a4aa5a90..473d9d0f00 100755
--- a/test/reline/yamatanooroti/multiline_repl
+++ b/test/reline/yamatanooroti/multiline_repl
@@ -59,12 +59,12 @@ opt.on('--dialog VAL') { |v|
if v.include?('scrollkey')
dialog.trap_key = nil
if key and key.match?(dialog.name)
- if context.pointer.nil?
- context.pointer = 0
- elsif context.pointer >= (contents.size - 1)
- context.pointer = 0
+ if dialog.pointer.nil?
+ dialog.pointer = 0
+ elsif dialog.pointer >= (contents.size - 1)
+ dialog.pointer = 0
else
- context.pointer += 1
+ dialog.pointer += 1
end
end
dialog.trap_key = [?j.ord]
@@ -74,8 +74,8 @@ opt.on('--dialog VAL') { |v|
if v.include?('scrollbar')
scrollbar = true
end
- Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, pointer: context.pointer, scrollbar: scrollbar)
- }, Struct.new(:pointer).new)
+ Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, scrollbar: scrollbar)
+ })
}
opt.on('--complete') {
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|