diff --git a/README.md b/README.md index 5629aba..0ecfd31 100644 --- a/README.md +++ b/README.md @@ -179,10 +179,12 @@ The follow actions are supported: - `down` -- cursor down (default: `j`) - `help_menu` -- show/hide help menu (default: `F1`) - `link_handler` -- cycle link handling (webbrowser, xdg-open, --run-safe or --run) (default: `l`) +- `next` -- jump to next URL (default: `J`) - `open_queue` -- open all URLs in queue (default: `o`) - `open_queue_win` -- open all URLs in queue in new window (default: `O`) - `open_url` -- open selected URL (default: `space` or `enter`) - `palette` -- cycle through palettes (default: `p`) +- `previous` -- jump to previous URL (default: `K`) - `quit` -- quit (default: `q` or `Q`) - `reverse` -- reverse display order (default: `R`) - `shorten` -- toggle shorten highlighted URL (default: `s`) diff --git a/urlscan.1 b/urlscan.1 index 1ac3cc1..9ab322a 100644 --- a/urlscan.1 +++ b/urlscan.1 @@ -188,6 +188,8 @@ The follow actions are supported: .TP \fBlink_handler\fR \-\- cycle link handling (webbrowser, xdg-open or custom) (Default: \fBl\fR) .TP +\fBnext\fR \-\- jump to next URL (Default: \fBJ\fR) +.TP \fBopen_queue\fR \-\- open all URLs in queue (Default: \fBo\fR) .TP \fBopen_queue_win\fR \-\- open all URLs in queue in new window (Default: \fBO\fR) @@ -196,6 +198,8 @@ The follow actions are supported: .TP \fBpalette\fR \-\- cycle through palettes (Default: \fBp\fR) .TP +\fBprevious\fR \-\- jump to previous URL (Default: \fBK\fR) +.TP \fBquit\fR \-\- quit (Default: \fBq\fR or \fBQ\fR) .TP \fBreverse\fR \-\- reverse display order (Default: \fBR\fR) diff --git a/urlscan/urlchoose.py b/urlscan/urlchoose.py index 3538db1..48e3994 100644 --- a/urlscan/urlchoose.py +++ b/urlscan/urlchoose.py @@ -118,6 +118,8 @@ def __init__(self, extractedurls, compact=False, reverse=False, nohelp=False, de 'g': self._top, 'j': self._down, 'k': self._up, + 'J': self._next, + 'K': self._previous, 'P': self._clipboard_pri, 'l': self._link_handler, 'o': self._open_queue, @@ -446,10 +448,12 @@ def _help_menu(self): "help_menu -- show/hide help menu\n" "link_handler -- cycle through xdg-open, webbrowser \n" " and user-defined function\n" + "next -- jump to next URL\n" "open_queue -- open all URLs in queue\n" "open_queue_win-- open all URLs in queue in new window\n" "open_url -- open selected URL\n" "palette -- cycle through palettes\n" + "previous -- jump to previous URL\n" "quit -- quit\n" "reverse -- reverse order URLs/context\n" "shorten -- toggle shorten highlighted URL\n" @@ -524,6 +528,31 @@ def _bottom(self): self.top.base_widget.body.focus_position = len(self.items) - 1 self.top.base_widget.keypress(self.size, "") # Trick urwid into redisplaying the cursor + def _selectable_positions(self): + return [i for i, item in enumerate(self.items) if item.selectable()] + + def _next(self): + """ J """ + current_position = self.top.base_widget.body.focus_position + if current_position >= self._selectable_positions()[-1]: + # Do not jump if focus is on or after the last selectable position + return + # Jump to the first selectable position after the currently focused position + target_position = min(p for p in self._selectable_positions() if p > current_position) + self.top.base_widget.body.focus_position = target_position + self.top.base_widget.keypress(self.size, "") # Trick urwid into redisplaying the cursor + + def _previous(self): + """ K """ + current_position = self.top.base_widget.body.focus_position + if current_position <= self._selectable_positions()[0]: + # Do not jump if focus is on or before the first selectable position + return + # Jump to the first selectable position before the currently focused position + target_position = max(p for p in self._selectable_positions() if p < current_position) + self.top.base_widget.body.focus_position = target_position + self.top.base_widget.keypress(self.size, "") # Trick urwid into redisplaying the cursor + def _shorten(self): """ s """ # Toggle shortened URL for selected item