summaryrefslogtreecommitdiff
path: root/src/bookmarks.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks.c')
-rw-r--r--src/bookmarks.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 67c6a25f..1a260f3a 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -327,11 +327,18 @@ void save_Bookmarks(const iBookmarks *d, const char *dirPath) {
327 unlock_Mutex(d->mtx); 327 unlock_Mutex(d->mtx);
328} 328}
329 329
330static int maxOrder_Bookmarks_(const iBookmarks *d) { 330static iRangei orderRange_Bookmarks_(const iBookmarks *d) {
331 int ord = 0; 331 iRangei ord = { 0, 0 };
332 iConstForEach(Hash, i, &d->bookmarks) { 332 iConstForEach(Hash, i, &d->bookmarks) {
333 const iBookmark *bm = (const iBookmark *) i.value; 333 const iBookmark *bm = (const iBookmark *) i.value;
334 ord = iMax(ord, bm->order); 334 if (isEmpty_Range(&ord)) {
335 ord.start = bm->order;
336 ord.end = bm->order + 1;
337 }
338 else {
339 ord.start = iMin(ord.start, bm->order);
340 ord.end = iMax(ord.end, bm->order + 1);
341 }
335 } 342 }
336 return ord; 343 return ord;
337} 344}
@@ -349,7 +356,13 @@ uint32_t add_Bookmarks(iBookmarks *d, const iString *url, const iString *title,
349 } 356 }
350 bm->icon = icon; 357 bm->icon = icon;
351 initCurrent_Time(&bm->when); 358 initCurrent_Time(&bm->when);
352 bm->order = maxOrder_Bookmarks_(d) + 1; /* Last in lists. */ 359 const iRangei ord = orderRange_Bookmarks_(d);
360 if (prefs_App()->addBookmarksToBottom) {
361 bm->order = ord.end; /* Last in lists. */
362 }
363 else {
364 bm->order = ord.start - 1; /* First in lists. */
365 }
353 insert_Bookmarks_(d, bm); 366 insert_Bookmarks_(d, bm);
354 unlock_Mutex(d->mtx); 367 unlock_Mutex(d->mtx);
355 return id_Bookmark(bm); 368 return id_Bookmark(bm);