Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Select with default occasionally not in frame #206

Open
apainintheneck opened this issue Dec 21, 2024 · 1 comment
Open

Bug: Select with default occasionally not in frame #206

apainintheneck opened this issue Dec 21, 2024 · 1 comment

Comments

@apainintheneck
Copy link

apainintheneck commented Dec 21, 2024

Are you in the right place?

  • For issues or feature requests file a GitHub issue in this repository
  • For general questions or discussion post in Discussions

Describe the problem

It seems like the default value is sometime out of frame with the select prompt.

Steps to reproduce the problem

tty-prompt-select-default-bug

Note that when the 20th position is the default value it is in frame but when the 18th position is the default value it is 2 lines above the visible content.

Actual behaviour

The default value was correct because clicking enter immediately provides the expected value but it is out of frame.

Expected behaviour

The default value should always start in frame and the cursor should always be in frame.

Describe your environment

  • OS version: macOS 10.15.7
  • Ruby version: 3.2.2
  • TTY::Prompt version: 0.23.1
  • Console: iTerm2, Terminal (default on macOS)
@apainintheneck
Copy link
Author

irb(main):038> TTY::Prompt::Paginator.new.paginate((1..25).map(&:to_s), 12, 6).to_a
=> [["18", 17], ["19", 18], ["20", 19], ["21", 20], ["22", 21], ["23", 22]]
irb(main):039> TTY::Prompt::Paginator.new.paginate((1..25).map(&:to_s), 18, 6).to_a
=> [["20", 19], ["21", 20], ["22", 21], ["23", 22], ["24", 23], ["25", 24]]

I think that the problem might be here in the TTY::Prompt::Paginator#paginate method.

diff --git a/lib/tty/prompt/paginator.rb b/lib/tty/prompt/paginator.rb
index d69d03d..bd8b327 100644
--- a/lib/tty/prompt/paginator.rb
+++ b/lib/tty/prompt/paginator.rb
@@ -77,7 +77,7 @@ module TTY
 
         step = (current_index - @last_index).abs
         if current_index > @last_index # going up
-          if current_index >= @end_index && current_index < list.size - 1
+          if current_index > @end_index && current_index < list.size - 1
             last_page = list.size - @per_page
             @start_index = [@start_index + step, last_page].min
           end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant