Skip to content

Commit

Permalink
Change the way scroll is handled. Fixes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
wong2 committed Nov 6, 2022
1 parent e3d2877 commit 74a312e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/pick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Picker(Generic[OPTION_T]):
min_selection_count: int = 0
selected_indexes: List[int] = field(init=False, default_factory=list)
index: int = field(init=False, default=0)
scroll_top: int = field(init=False, default=0)

def __post_init__(self) -> None:
if len(self.options) == 0:
Expand Down Expand Up @@ -122,12 +121,11 @@ def draw(self, screen) -> None:
lines, current_line = self.get_lines()

# calculate how many lines we should scroll, relative to the top
if current_line <= self.scroll_top:
self.scroll_top = 0
elif current_line - self.scroll_top > max_rows:
self.scroll_top = current_line - max_rows
scroll_top = 0
if current_line > max_rows:
scroll_top = current_line - max_rows

lines_to_draw = lines[self.scroll_top : self.scroll_top + max_rows]
lines_to_draw = lines[scroll_top : scroll_top + max_rows]

for line in lines_to_draw:
screen.addnstr(y, x, line, max_x - 2)
Expand Down

0 comments on commit 74a312e

Please sign in to comment.