browser: add missing horizontal scrolling features

exec
dece 3 years ago
parent 535ab0aa16
commit cee04f10c7

@ -102,7 +102,7 @@ class Browser:
elif char == ord("h"):
self.scroll_page_horizontally(-3)
elif char == ord("H"):
pass # TODO h-scroll whole page left
self.scroll_whole_page_left()
elif char == ord("j"):
self.scroll_page_vertically(3)
elif char == ord("J"):
@ -114,9 +114,9 @@ class Browser:
elif char == ord("l"):
self.scroll_page_horizontally(3)
elif char == ord("L"):
pass # TODO h-scroll whole page right
self.scroll_whole_page_right()
elif char == ord("^"):
pass # TODO reset horizontal scrolling
self.scroll_page_horizontally(-inf)
elif char == ord("g"):
char = self.screen.getch()
if char == ord("g"):
@ -382,10 +382,27 @@ class Browser:
self.scroll_page_vertically(-self.page_pad_size[0])
def scroll_page_horizontally(self, by_columns):
"""Scroll page horizontally."""
if self.page_pad.scroll_h(by_columns, self.w):
"""Scroll page horizontally.
If `by_lines` is an integer (positive or negative), scroll the page by
this amount of columns. If `by_lines` is -inf, scroll back to the first
column. Scrolling to the right-most column is not supported.
"""
if by_columns == -inf:
require_refresh = self.page_pad.go_to_first_column()
else:
require_refresh = self.page_pad.scroll_h(by_columns, self.w)
if require_refresh:
self.refresh_page()
def scroll_whole_page_left(self):
"""Scroll left by a whole page."""
self.scroll_page_horizontally(-self.page_pad_size[1])
def scroll_whole_page_right(self):
"""Scroll right by a whole page."""
self.scroll_page_horizontally(self.page_pad_size[1])
def reload_page(self):
"""Reload the page, if one has been previously loaded."""
if self.current_url:

@ -98,3 +98,10 @@ class PagePad:
self.current_line = max_line
return True
return False
def go_to_first_column(self):
"""Move to the first column; return True if a refresh is needed."""
if self.current_column:
self.current_column = 0
return True
return False

Loading…
Cancel
Save