Merge branch 'ismail-s-add-bookmark-by-url'

This commit is contained in:
Florian Bruhin 2016-07-11 20:55:38 +02:00
commit cb84cbf730
5 changed files with 52 additions and 6 deletions

View File

@ -34,6 +34,8 @@ Changed
`gg` can be used with a count.
- Aliases can now use `;;` to have an alias which executed multiple commands.
- `:edit-url` now does nothing if the URL isn't changed in the spawned editor.
- `:bookmark-add` can now be passed a URL and title to add that as a bookmark
rather than the current page.
Removed
-------

View File

@ -179,6 +179,7 @@ Contributors, sorted by the number of commits in descending order:
* skinnay
* Zach-Button
* Tomasz Kramkowski
* Ismail S
* Halfwit
* rikn00
* kanikaa1234

View File

@ -8,7 +8,7 @@
|<<adblock-update,adblock-update>>|Update the adblock block lists.
|<<back,back>>|Go back in the history of the current tab.
|<<bind,bind>>|Bind a key to a command.
|<<bookmark-add,bookmark-add>>|Save the current page as a bookmark.
|<<bookmark-add,bookmark-add>>|Save the current page as a bookmark, or a specific url.
|<<bookmark-del,bookmark-del>>|Delete a bookmark.
|<<bookmark-load,bookmark-load>>|Load a bookmark.
|<<buffer,buffer>>|Select tab by index or url/title best match.
@ -116,7 +116,15 @@ Bind a key to a command.
[[bookmark-add]]
=== bookmark-add
Save the current page as a bookmark.
Syntax: +:bookmark-add ['url'] ['title']+
Save the current page as a bookmark, or a specific url.
If no url and title are provided, then save the current page as a bookmark. If a url and title have been provided, then save the given url as a bookmark with the provided title.
==== positional arguments
* +'url'+: url to save as a bookmark. If None, use url of current page.
* +'title'+: title of the new bookmark.
[[bookmark-del]]
=== bookmark-del

View File

@ -1081,12 +1081,33 @@ class CommandDispatcher:
self._open(url, tab, bg, window)
@cmdutils.register(instance='command-dispatcher', scope='window')
def bookmark_add(self):
"""Save the current page as a bookmark."""
def bookmark_add(self, url=None, title=None):
"""Save the current page as a bookmark, or a specific url.
If no url and title are provided, then save the current page as a
bookmark.
If a url and title have been provided, then save the given url as
a bookmark with the provided title.
Args:
url: url to save as a bookmark. If None, use url of current page.
title: title of the new bookmark.
"""
if url and not title:
raise cmdexc.CommandError('Title must be provided if url has '
'been provided')
bookmark_manager = objreg.get('bookmark-manager')
url = self._current_url()
if url is None:
url = self._current_url()
else:
try:
url = urlutils.fuzzy_url(url)
except urlutils.InvalidUrlError as e:
raise cmdexc.CommandError(e)
if not title:
title = self._current_title()
try:
bookmark_manager.add(url, self._current_title())
bookmark_manager.add(url, title)
except urlmarks.Error as e:
raise cmdexc.CommandError(str(e))
else:

View File

@ -8,6 +8,20 @@ Feature: quickmarks and bookmarks
Then the message "Bookmarked http://localhost:*/data/title.html!" should be shown
And the bookmark file should contain "http://localhost:*/data/title.html Test title"
Scenario: Saving a bookmark with a provided url and title
When I run :bookmark-add http://example.com "some example title"
Then the message "Bookmarked http://example.com!" should be shown
And the bookmark file should contain "http://example.com some example title"
Scenario: Saving a bookmark with a url but no title
When I run :bookmark-add http://example.com
Then the error "Title must be provided if url has been provided" should be shown
Scenario: Saving a bookmark with an invalid url
When I set general -> auto-search to false
And I run :bookmark-add foo! "some example title"
Then the error "Invalid URL" should be shown
Scenario: Saving a duplicate bookmark
Given I have a fresh instance
When I open data/title.html