diff --git a/services/sync/modules/engines/bookmarks.js b/services/sync/modules/engines/bookmarks.js index 1d096f5ebc7..ede0c04c5c9 100644 --- a/services/sync/modules/engines/bookmarks.js +++ b/services/sync/modules/engines/bookmarks.js @@ -99,20 +99,40 @@ BookmarksEngine.prototype = { _syncStartup: function _syncStart() { SyncEngine.prototype._syncStartup.call(this); - // Lazily create a mapping of folder titles to ids if necessary - this.__defineGetter__("_folderTitles", function() { + // Lazily create a mapping of folder titles and separator positions to GUID + let lazyMap = function() { delete this._folderTitles; + delete this._separatorPos; let folderTitles = {}; + let separatorPos = {}; for (let guid in this._store.getAllIDs()) { let id = idForGUID(guid); - if (Svc.Bookmark.getItemType(id) != Svc.Bookmark.TYPE_FOLDER) - continue; - - folderTitles[Svc.Bookmark.getItemTitle(id)] = guid; + switch (Svc.Bookmark.getItemType(id)) { + case Svc.Bookmark.TYPE_FOLDER: + // Map the folder name to GUID + folderTitles[Svc.Bookmark.getItemTitle(id)] = guid; + break; + case Svc.Bookmark.TYPE_SEPARATOR: + // Map the separator position and parent position to GUID + let parent = Svc.Bookmark.getFolderIdForItem(id); + let pos = [id, parent].map(Svc.Bookmark.getItemIndex); + separatorPos[pos] = guid; + break; + } } - return this._folderTitles = folderTitles; - }); + + this._folderTitles = folderTitles; + this._separatorPos = separatorPos; + }; + + // Make the getters that lazily build the mapping + ["_folderTitles", "_separatorPos"].forEach(function(lazy) { + this.__defineGetter__(lazy, function() { + lazyMap.call(this); + return this[lazy]; + }); + }, this); }, _syncFinish: function _syncFinish() { @@ -134,6 +154,8 @@ BookmarksEngine.prototype = { case "folder": case "livemark": return this._folderTitles[item.title]; + case "separator": + return this._separatorPos[item.pos]; } // TODO for bookmarks, check if it exists and find guid // for everything else (folders, separators) look for parent/pred? @@ -717,6 +739,9 @@ BookmarksStore.prototype = { case this._bms.TYPE_SEPARATOR: record = new BookmarkSeparator(); + // Create a positioning identifier for the separator + let parent = Svc.Bookmark.getFolderIdForItem(placeId); + record.pos = [placeId, parent].map(Svc.Bookmark.getItemIndex); break; case this._bms.TYPE_DYNAMIC_CONTAINER: diff --git a/services/sync/modules/type_records/bookmark.js b/services/sync/modules/type_records/bookmark.js index f16909398f7..132a41146bb 100644 --- a/services/sync/modules/type_records/bookmark.js +++ b/services/sync/modules/type_records/bookmark.js @@ -183,3 +183,5 @@ BookmarkSeparator.prototype = { this.type = "separator"; } }; + +Utils.deferGetSet(BookmarkSeparator, "cleartext", "pos");