mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix note paths
This commit is contained in:
parent
119d7367da
commit
f59f08fa0e
@ -163,29 +163,10 @@ function registerEntrypoints() {
|
||||
$("#toggle-fullscreen-button").hide();
|
||||
}
|
||||
|
||||
// FIXME: do we really need these at this point?
|
||||
utils.bindShortcut("ctrl+shift+up", () => {
|
||||
const node = treeService.getActiveNode();
|
||||
node.navigate($.ui.keyCode.UP, true);
|
||||
|
||||
$("#note-detail-text").focus();
|
||||
});
|
||||
|
||||
|
||||
// FIXME: do we really need these at this point?
|
||||
utils.bindShortcut("ctrl+shift+down", () => {
|
||||
const node = treeService.getActiveNode();
|
||||
node.navigate($.ui.keyCode.DOWN, true);
|
||||
|
||||
$("#note-detail-text").focus();
|
||||
});
|
||||
|
||||
if (utils.isElectron()) {
|
||||
utils.bindShortcut('ctrl+-', zoomService.decreaseZoomFactor);
|
||||
utils.bindShortcut('ctrl+=', zoomService.increaseZoomFactor);
|
||||
}
|
||||
|
||||
$("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus());
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -17,6 +17,8 @@ import noteDetailRender from "./note_detail_render.js";
|
||||
import noteDetailRelationMap from "./note_detail_relation_map.js";
|
||||
import noteDetailProtectedSession from "./note_detail_protected_session.js";
|
||||
import protectedSessionService from "./protected_session.js";
|
||||
import linkService from "./link.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
|
||||
const $tabContentsContainer = $("#note-tab-container");
|
||||
|
||||
@ -49,6 +51,8 @@ class TabContext {
|
||||
|
||||
this.$noteTitle = this.$tabContent.find(".note-title");
|
||||
this.$noteTitleRow = this.$tabContent.find(".note-title-row");
|
||||
this.$notePathList = this.$tabContent.find(".note-path-list");
|
||||
this.$notePathCount = this.$tabContent.find(".note-path-count");
|
||||
this.$noteDetailComponents = this.$tabContent.find(".note-detail-component");
|
||||
this.$childrenOverview = this.$tabContent.find(".children-overview");
|
||||
this.$scriptArea = this.$tabContent.find(".note-detail-script-area");
|
||||
@ -72,6 +76,8 @@ class TabContext {
|
||||
treeService.setNoteTitle(this.noteId, title);
|
||||
});
|
||||
|
||||
this.$noteTitle.bind('keydown', 'return', () => this.getComponent().focus());
|
||||
|
||||
this.$protectButton = this.$tabContent.find(".protect-button");
|
||||
this.$protectButton.click(protectedSessionService.protectNoteAndSendToServer);
|
||||
|
||||
@ -110,6 +116,8 @@ class TabContext {
|
||||
this.noteType.updateExecuteScriptButtonVisibility();
|
||||
}
|
||||
|
||||
this.showPaths();
|
||||
|
||||
console.log(`Switched tab ${this.tabId} to ${this.noteId}`);
|
||||
}
|
||||
|
||||
@ -253,6 +261,52 @@ class TabContext {
|
||||
|
||||
this.$childrenOverview.show();
|
||||
}
|
||||
|
||||
async addPath(notePath, isCurrent) {
|
||||
const title = await treeUtils.getNotePathTitle(notePath);
|
||||
|
||||
const noteLink = await linkService.createNoteLink(notePath, title);
|
||||
|
||||
noteLink
|
||||
.addClass("no-tooltip-preview")
|
||||
.addClass("dropdown-item");
|
||||
|
||||
if (isCurrent) {
|
||||
noteLink.addClass("current");
|
||||
}
|
||||
|
||||
this.$notePathList.append(noteLink);
|
||||
}
|
||||
|
||||
async showPaths() {
|
||||
if (this.note.noteId === 'root') {
|
||||
// root doesn't have any parent, but it's still technically 1 path
|
||||
|
||||
this.$notePathCount.html("1 path");
|
||||
|
||||
this.$notePathList.empty();
|
||||
|
||||
await this.addPath('root', true);
|
||||
}
|
||||
else {
|
||||
const parents = await this.note.getParentNotes();
|
||||
|
||||
this.$notePathCount.html(parents.length + " path" + (parents.length > 1 ? "s" : ""));
|
||||
this.$notePathList.empty();
|
||||
|
||||
const pathSegments = this.notePath.split("/");
|
||||
const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
|
||||
|
||||
for (const parentNote of parents) {
|
||||
const parentNotePath = await treeService.getSomeNotePath(parentNote);
|
||||
// this is to avoid having root notes leading '/'
|
||||
const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId;
|
||||
const isCurrent = activeNoteParentNoteId === parentNote.noteId;
|
||||
|
||||
await this.addPath(notePath, isCurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default TabContext;
|
@ -22,8 +22,6 @@ const $tree = $("#tree");
|
||||
const $createTopLevelNoteButton = $("#create-top-level-note-button");
|
||||
const $collapseTreeButton = $("#collapse-tree-button");
|
||||
const $scrollToActiveNoteButton = $("#scroll-to-active-note-button");
|
||||
const $notePathList = $("#note-path-list");
|
||||
const $notePathCount = $("#note-path-count");
|
||||
|
||||
// focused & not active node can happen during multiselection where the node is selected but not activated
|
||||
// (its content is not displayed in the detail)
|
||||
@ -267,54 +265,6 @@ async function getRunPath(notePath) {
|
||||
return effectivePath.reverse();
|
||||
}
|
||||
|
||||
async function addPath(notePath, isCurrent) {
|
||||
const title = await treeUtils.getNotePathTitle(notePath);
|
||||
|
||||
const noteLink = await linkService.createNoteLink(notePath, title);
|
||||
|
||||
noteLink
|
||||
.addClass("no-tooltip-preview")
|
||||
.addClass("dropdown-item");
|
||||
|
||||
if (isCurrent) {
|
||||
noteLink.addClass("current");
|
||||
}
|
||||
|
||||
$notePathList.append(noteLink);
|
||||
}
|
||||
|
||||
async function showPaths(noteId, node) {
|
||||
utils.assertArguments(noteId, node);
|
||||
|
||||
const note = await treeCache.getNote(noteId);
|
||||
|
||||
if (note.noteId === 'root') {
|
||||
// root doesn't have any parent, but it's still technically 1 path
|
||||
|
||||
$notePathCount.html("1 path");
|
||||
|
||||
$notePathList.empty();
|
||||
|
||||
await addPath('root', true);
|
||||
}
|
||||
else {
|
||||
const parents = await note.getParentNotes();
|
||||
|
||||
$notePathCount.html(parents.length + " path" + (parents.length > 1 ? "s" : ""));
|
||||
|
||||
$notePathList.empty();
|
||||
|
||||
for (const parentNote of parents) {
|
||||
const parentNotePath = await getSomeNotePath(parentNote);
|
||||
// this is to avoid having root notes leading '/'
|
||||
const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId;
|
||||
const isCurrent = node.getParent().data.noteId === parentNote.noteId;
|
||||
|
||||
await addPath(notePath, isCurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getSomeNotePath(note) {
|
||||
utils.assertArguments(note);
|
||||
|
||||
@ -328,7 +278,7 @@ async function getSomeNotePath(note) {
|
||||
const parents = await cur.getParentNotes();
|
||||
|
||||
if (!parents.length) {
|
||||
infoService.throwError("Can't find parents for ", cur);
|
||||
infoService.throwError(`Can't find parents for note ${cur.noteId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -468,8 +418,6 @@ function initFancyTree(tree) {
|
||||
const notePath = await treeUtils.getNotePath(node);
|
||||
|
||||
noteDetailService.switchToNote(notePath);
|
||||
|
||||
showPaths(noteId, node);
|
||||
},
|
||||
expand: (event, data) => setExpandedToServer(data.node.data.branchId, true),
|
||||
collapse: (event, data) => setExpandedToServer(data.node.data.branchId, false),
|
||||
|
Loading…
x
Reference in New Issue
Block a user