mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
search can be triggered from URL, closes #385
This commit is contained in:
parent
b59c175c2e
commit
a87f4d8653
@ -121,6 +121,8 @@ $("#export-note-button").click(function () {
|
|||||||
|
|
||||||
macInit.init();
|
macInit.init();
|
||||||
|
|
||||||
|
searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash
|
||||||
|
|
||||||
treeService.showTree();
|
treeService.showTree();
|
||||||
|
|
||||||
entrypoints.registerEntrypoints();
|
entrypoints.registerEntrypoints();
|
||||||
|
@ -76,6 +76,15 @@ async function saveSearch() {
|
|||||||
await treeService.activateNote(noteId);
|
await treeService.activateNote(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
const hashValue = treeService.getHashValueFromAddress();
|
||||||
|
|
||||||
|
if (hashValue.startsWith("search=")) {
|
||||||
|
showSearch();
|
||||||
|
doSearch(hashValue.substr(7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$searchInput.keyup(e => {
|
$searchInput.keyup(e => {
|
||||||
const searchText = $searchInput.val();
|
const searchText = $searchInput.val();
|
||||||
|
|
||||||
@ -100,5 +109,6 @@ export default {
|
|||||||
toggleSearch,
|
toggleSearch,
|
||||||
resetSearch,
|
resetSearch,
|
||||||
showSearch,
|
showSearch,
|
||||||
doSearch
|
doSearch,
|
||||||
|
init
|
||||||
};
|
};
|
@ -483,16 +483,20 @@ async function reload() {
|
|||||||
await getTree().reload(notes);
|
await getTree().reload(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNotePathFromAddress() {
|
function isNotePathInAddress() {
|
||||||
return document.location.hash.substr(1); // strip initial #
|
return getHashValueFromAddress().startsWith("root");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHashValueFromAddress() {
|
||||||
|
return document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadTree() {
|
async function loadTree() {
|
||||||
const resp = await server.get('tree');
|
const resp = await server.get('tree');
|
||||||
startNotePath = resp.startNotePath;
|
startNotePath = resp.startNotePath;
|
||||||
|
|
||||||
if (document.location.hash) {
|
if (isNotePathInAddress()) {
|
||||||
startNotePath = getNotePathFromAddress();
|
startNotePath = getHashValueFromAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
return await treeBuilder.prepareTree(resp.notes, resp.branches, resp.relations);
|
return await treeBuilder.prepareTree(resp.notes, resp.branches, resp.relations);
|
||||||
@ -707,12 +711,14 @@ utils.bindShortcut('ctrl+p', createNoteInto);
|
|||||||
utils.bindShortcut('ctrl+.', scrollToCurrentNote);
|
utils.bindShortcut('ctrl+.', scrollToCurrentNote);
|
||||||
|
|
||||||
$(window).bind('hashchange', function() {
|
$(window).bind('hashchange', function() {
|
||||||
const notePath = getNotePathFromAddress();
|
if (isNotePathInAddress()) {
|
||||||
|
const notePath = getHashValueFromAddress();
|
||||||
|
|
||||||
if (notePath !== '-' && getCurrentNotePath() !== notePath) {
|
if (notePath !== '-' && getCurrentNotePath() !== notePath) {
|
||||||
console.debug("Switching to " + notePath + " because of hash change");
|
console.debug("Switching to " + notePath + " because of hash change");
|
||||||
|
|
||||||
activateNote(notePath);
|
activateNote(notePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -745,5 +751,6 @@ export default {
|
|||||||
showTree,
|
showTree,
|
||||||
loadTree,
|
loadTree,
|
||||||
treeInitialized,
|
treeInitialized,
|
||||||
setExpandedToServer
|
setExpandedToServer,
|
||||||
|
getHashValueFromAddress
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user