browser: add missing horizontal scrolling features

This commit is contained in:
dece 2021-04-17 22:02:06 +02:00
parent 535ab0aa16
commit cee04f10c7
2 changed files with 29 additions and 5 deletions

View file

@ -102,7 +102,7 @@ class Browser:
elif char == ord("h"): elif char == ord("h"):
self.scroll_page_horizontally(-3) self.scroll_page_horizontally(-3)
elif char == ord("H"): elif char == ord("H"):
pass # TODO h-scroll whole page left self.scroll_whole_page_left()
elif char == ord("j"): elif char == ord("j"):
self.scroll_page_vertically(3) self.scroll_page_vertically(3)
elif char == ord("J"): elif char == ord("J"):
@ -114,9 +114,9 @@ class Browser:
elif char == ord("l"): elif char == ord("l"):
self.scroll_page_horizontally(3) self.scroll_page_horizontally(3)
elif char == ord("L"): elif char == ord("L"):
pass # TODO h-scroll whole page right self.scroll_whole_page_right()
elif char == ord("^"): elif char == ord("^"):
pass # TODO reset horizontal scrolling self.scroll_page_horizontally(-inf)
elif char == ord("g"): elif char == ord("g"):
char = self.screen.getch() char = self.screen.getch()
if char == ord("g"): if char == ord("g"):
@ -382,10 +382,27 @@ class Browser:
self.scroll_page_vertically(-self.page_pad_size[0]) self.scroll_page_vertically(-self.page_pad_size[0])
def scroll_page_horizontally(self, by_columns): def scroll_page_horizontally(self, by_columns):
"""Scroll page horizontally.""" """Scroll page horizontally.
if self.page_pad.scroll_h(by_columns, self.w):
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() 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): def reload_page(self):
"""Reload the page, if one has been previously loaded.""" """Reload the page, if one has been previously loaded."""
if self.current_url: if self.current_url:

View file

@ -98,3 +98,10 @@ class PagePad:
self.current_line = max_line self.current_line = max_line
return True return True
return False 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