mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-12-04 22:00:06 -05:00
Wrap browser keypress handler to avoid crash on intermittent listbox invalid offset
This commit is contained in:
parent
1d99e0dca6
commit
d2de625e5f
1 changed files with 21 additions and 15 deletions
|
|
@ -161,24 +161,30 @@ class PageList(urwid.ListBox):
|
||||||
return unhandled_key
|
return unhandled_key
|
||||||
|
|
||||||
def handle_key(self, size, key):
|
def handle_key(self, size, key):
|
||||||
if key in ("page up", "page down", "home", "end"):
|
try:
|
||||||
focus_widget = self.focus
|
if key in ("page up", "page down", "home", "end"):
|
||||||
if focus_widget is not None and focus_widget.selectable():
|
focus_widget = self.focus
|
||||||
key = focus_widget.keypress((size[0],), key)
|
if focus_widget is not None and focus_widget.selectable():
|
||||||
if key is None:
|
key = focus_widget.keypress((size[0],), key)
|
||||||
self.make_cursor_visible(size)
|
if key is None:
|
||||||
return None
|
self.make_cursor_visible(size)
|
||||||
|
return None
|
||||||
|
|
||||||
if key == "page down": self.scroll(size[1] - 1)
|
if key == "page down": self.scroll(size[1] - 1)
|
||||||
elif key == "page up": self.scroll(1 - size[1])
|
elif key == "page up": self.scroll(1 - size[1])
|
||||||
elif key == "home": self.set_scrollpos(0)
|
elif key == "home": self.set_scrollpos(0)
|
||||||
elif key == "end": self.set_scrollpos(self.rows_max(size))
|
elif key == "end": self.set_scrollpos(self.rows_max(size))
|
||||||
|
return None
|
||||||
|
|
||||||
|
unhandled_key = super().keypress(size, key)
|
||||||
|
if key in ("up", "down"): return None
|
||||||
|
return unhandled_key
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Error while handling browser keypress: {e}", RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
unhandled_key = super().keypress(size, key)
|
|
||||||
if key in ("up", "down"): return None
|
|
||||||
return unhandled_key
|
|
||||||
|
|
||||||
def mouse_event(self, size, event, button, col, row, focus):
|
def mouse_event(self, size, event, button, col, row, focus):
|
||||||
self._page_size = size
|
self._page_size = size
|
||||||
if button in (4, 5): return False
|
if button in (4, 5): return False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue