make it again possible to open notes through URL hash

This commit is contained in:
zadam
2019-07-09 22:12:05 +02:00
parent 6a99af64a8
commit 3d7a5f20e7
4 changed files with 214 additions and 204 deletions

View File

@@ -196,6 +196,8 @@ async function resolveNotePath(notePath) {
async function getRunPath(notePath) {
utils.assertArguments(notePath);
notePath = notePath.split("-")[0];
const path = notePath.split("/").reverse();
if (!path.includes("root")) {
@@ -335,6 +337,31 @@ async function treeInitialized() {
messagingService.logError("Cannot retrieve open tabs: " + e.stack);
}
// if there's notePath in the URL, make sure it's open and active
// (useful, among others, for opening clipped notes from clipper)
if (location.hash) {
const notePath = location.hash.substr(1);
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
if (await treeCache.noteExists(noteId)) {
for (const tab of openTabs) {
tab.active = false;
}
const foundTab = openTabs.find(tab => noteId === treeUtils.getNoteIdFromNotePath(tab.notePath));
if (foundTab) {
foundTab.active = true;
}
else {
openTabs.push({
notePath: notePath,
active: true
});
}
}
}
const filteredTabs = [];
for (const openTab of openTabs) {