firecat53 / urlscan

Mutt and terminal url selector (similar to urlview)
GNU General Public License v2.0
211 stars 36 forks source link

Feature suggestion: Jump directly to next/previous URL #151

Closed ilekka closed 1 month ago

ilekka commented 1 month ago

When context view is enabled and the next URL is not visible on the screen, pressing j does not go directly to the next URL; instead, it seems to scroll down one line at a time until the URL is reached. The same applies to pressing k if the previous URL is off the screen.

Here I attempted to create the possibility to jump directly to the next/previous URL (bound to J and K by default.) This is done by creating a list of selectable item positions when the URLChooser class is initialized and adding functions which change focus to the next or previous position on the list according to the currently focused position.

Any comments are very welcome, especially if you see there is something wrong with my approach or the same outcome could have been achieved in some simpler way. This is very much possible as I am not experienced with urwid at all.

firecat53 commented 1 month ago

Brilliant! That's been a long standing minor annoyance that I haven't fixed. Works perfectly...except when in compact mode where it fails pretty hard (crashes).

If you can fix that and update the README and man page with new keybindings I'll definitely merge this.

I'm not going to look and see if it can be simplified at this point. I'm no expert either and it works!

Thanks!!

ilekka commented 1 month ago

Right - I forgot that the selectable positions must be updated if the items list itself is changed. This happens not only when context is switched on/off, but also after reversing the URLs and searching.

To fix this, I created a method in the URLChooser class which gets the selectable positions corresponding to the current list of items. In principle this seems slightly wasteful, since the selectable positions are now recalculated every time, even if there is no need to update them. However, in practice I couldn't actually see any visible difference in performance, not even on a very low-powered machine.

I have also added the new keybindings to the documentation.

firecat53 commented 1 month ago

Awesome, works great! Thanks for the contribution and the interest!

ilekka commented 1 month ago

Thank you for merging!