🐛 Don't allow creation of invalid bkmks - fixes #95

This commit is contained in:
makeworld 2020-10-01 19:08:26 -04:00
parent 5186a585b3
commit efc10a2b3e

View File

@ -134,16 +134,22 @@ func Bookmarks(t *tab) {
// It is the high-level way of doing it. It should be called in a goroutine. // It is the high-level way of doing it. It should be called in a goroutine.
// It can also be called to edit an existing bookmark. // It can also be called to edit an existing bookmark.
func addBookmark() { func addBookmark() {
curPage := tabs[curTab].page t := tabs[curTab]
name, exists := bookmarks.Get(curPage.URL) p := t.page
if !t.hasContent() {
// It's an about: page, or a malformed one
return
}
name, exists := bookmarks.Get(p.URL)
// Open a bookmark modal with the current name of the bookmark, if it exists // Open a bookmark modal with the current name of the bookmark, if it exists
newName, action := openBkmkModal(name, exists, curPage.Favicon) newName, action := openBkmkModal(name, exists, p.Favicon)
switch action { switch action {
case 1: case 1:
// Add/change the bookmark // Add/change the bookmark
bookmarks.Set(tabs[curTab].page.URL, newName) bookmarks.Set(p.URL, newName)
case -1: case -1:
bookmarks.Remove(tabs[curTab].page.URL) bookmarks.Remove(p.URL)
} }
// Other case is action = 0, meaning "Cancel", so nothing needs to happen // Other case is action = 0, meaning "Cancel", so nothing needs to happen
} }