Allow browser storage plugin to delete existing tiddlers (#6625)

* Do not remove localstorage items while looping

While looping over all the browser storage items by index, the items
should not be removed because removing alters the index positions. The
item following the removed one will be skipped by the loop.

Instead, accumulate a list of keys to remove and remove them after the
loop.

* Implement full delete support for browser storage plugin

Before, deletes only worked for tiddlers which are only present in the
localstorage. Now deleted tiddlers are marked in localstorage using an
empty string value.

At startup, the localstorage tiddlers with empty strings will be deleted
from the wiki if they are still present. If they are already gone from
the wiki, then the blank localstorage entry will be deleted.

* Document drawbacks to using '[all[]]' and provide an alternative
This commit is contained in:
btheado
2022-04-12 17:11:37 -04:00
committed by GitHub
parent 73138b79aa
commit 8a9d48e055
4 changed files with 28 additions and 5 deletions

View File

@@ -100,9 +100,12 @@ function saveTiddlerToLocalStorage(title,options) {
}
}
} else {
console.log("browser-storage: Deleting",title);
// In local storage, use the special value of empty string to mark the tiddler as deleted
// On future page loads, if the tiddler is already gone from startup then the blank entry
// will be removed from localstorage. Otherwise, the tiddler will be deleted.
console.log("browser-storage: Blanking",title);
try {
window.localStorage.removeItem(options.prefix + title);
window.localStorage.setItem(options.prefix + title, "");
} catch(e) {
console.log("Browser-storage error:",e);
}