Add :navigate strip

This commit is contained in:
Stefan Strogin 2018-11-26 04:16:04 +02:00
parent a2ba0b4c76
commit f70c347dfa
6 changed files with 30 additions and 2 deletions

View File

@ -34,6 +34,8 @@ Added
are used for hints, and also allows adding custom hint groups.
- New `:yank markdown` feature which yanks the current URL and title in
markdown format.
- New command `:navigate strip` which removes queries and parameters from the
current URL (bound to `gs`/`gS` by default).
Changed
~~~~~~~

View File

@ -827,6 +827,7 @@ This tries to automatically click on typical _Previous Page_ or _Next Page_ link
Uses the
link:settings{outsuffix}#url.incdec_segments[url.incdec_segments]
config option.
- `strip`: Strip parameters from the current URL.

View File

@ -575,6 +575,7 @@ Default:
* +pass:[gC]+: +pass:[tab-clone]+
* +pass:[gD]+: +pass:[tab-give]+
* +pass:[gO]+: +pass:[set-cmd-text :open -t -r {url:pretty}]+
* +pass:[gS]+: +pass:[navigate strip -t]+
* +pass:[gU]+: +pass:[navigate up -t]+
* +pass:[g^]+: +pass:[tab-focus 1]+
* +pass:[ga]+: +pass:[open -t]+
@ -587,6 +588,7 @@ Default:
* +pass:[gm]+: +pass:[tab-move]+
* +pass:[go]+: +pass:[set-cmd-text :open {url:pretty}]+
* +pass:[gr]+: +pass:[tab-move +]+
* +pass:[gs]+: +pass:[navigate strip]+
* +pass:[gt]+: +pass:[set-cmd-text -s :buffer]+
* +pass:[gu]+: +pass:[navigate up]+
* +pass:[h]+: +pass:[scroll left]+

View File

@ -599,7 +599,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment',
'decrement'])
'decrement', 'strip'])
@cmdutils.argument('count', count=True)
def navigate(self, where: str, tab=False, bg=False, window=False, count=1):
"""Open typical prev/next links or navigate using the URL path.
@ -623,6 +623,7 @@ class CommandDispatcher:
Uses the
link:settings{outsuffix}#url.incdec_segments[url.incdec_segments]
config option.
- `strip`: Strip parameters from the current URL.
tab: Open in a new tab.
bg: Open in a background tab.
@ -657,6 +658,9 @@ class CommandDispatcher:
url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
new_url = handlers[where](url, count)
self._open(new_url, tab, bg, window, related=True)
elif where == 'strip':
url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
self._open(url, tab, bg, window, related=True)
else: # pragma: no cover
raise ValueError("Got called with invalid value {} for "
"`where'.".format(where))

View File

@ -2646,6 +2646,8 @@ bindings.default:
"}}": navigate next -t
gu: navigate up
gU: navigate up -t
gs: navigate strip
gS: navigate strip -t
<Ctrl-A>: navigate increment
<Ctrl-X>: navigate decrement
wi: inspector

View File

@ -4,7 +4,7 @@ Feature: Using :navigate
Scenario: :navigate with invalid argument
When I run :navigate foo
Then the error "where: Invalid value foo - expected one of: prev, next, up, increment, decrement" should be shown
Then the error "where: Invalid value foo - expected one of: prev, next, up, increment, decrement, strip" should be shown
# up
@ -136,3 +136,20 @@ Feature: Using :navigate
When I open data/navigate/multilinelinks.html
And I run :navigate next
Then data/numbers/5.txt should be loaded
# strip
Scenario: Stripping a query
When I open data/navigate?foo=bar
And I run :navigate strip
Then data/navigate should be loaded
Scenario: Stripping a label
When I open data/navigate#label
And I run :navigate strip
Then data/navigate should be loaded
Scenario: Stripping a query and a label
When I open data/navigate?foo=bar#label
And I run :navigate strip
Then data/navigate should be loaded