mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes in working with top level nodes and root node
This commit is contained in:
parent
14f44b3271
commit
8bc12a2654
@ -222,6 +222,7 @@ const noteTree = (function() {
|
||||
assertArguments(notePath);
|
||||
|
||||
const runPath = getRunPath(notePath);
|
||||
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||
|
||||
let parentNoteId = 'root';
|
||||
@ -277,10 +278,14 @@ const noteTree = (function() {
|
||||
if (parents.length > 0) {
|
||||
console.log(now(), "Available parents:", parents);
|
||||
|
||||
const pathToRoot = getSomeNotePath(parents[0]).split("/").reverse();
|
||||
const someNotePath = getSomeNotePath(parents[0]);
|
||||
|
||||
for (const noteId of pathToRoot) {
|
||||
effectivePath.push(noteId);
|
||||
if (someNotePath) { // in case it's root the path may be empty
|
||||
const pathToRoot = someNotePath.split("/").reverse();
|
||||
|
||||
for (const noteId of pathToRoot) {
|
||||
effectivePath.push(noteId);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -58,7 +58,7 @@ const treeChanges = (function() {
|
||||
|
||||
await server.remove('notes/' + node.data.note_tree_id);
|
||||
|
||||
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
|
||||
if (!isTopLevelNode(node) && node.getParent().getChildren().length <= 1) {
|
||||
node.getParent().folder = false;
|
||||
node.getParent().renderTitle();
|
||||
}
|
||||
@ -69,27 +69,30 @@ const treeChanges = (function() {
|
||||
next = node.getPrevSibling();
|
||||
}
|
||||
|
||||
if (!next) {
|
||||
if (!next && !isTopLevelNode(node)) {
|
||||
next = node.getParent();
|
||||
}
|
||||
|
||||
node.remove();
|
||||
|
||||
// activate next element after this one is deleted so we don't lose focus
|
||||
next.setActive();
|
||||
if (next) {
|
||||
// activate next element after this one is deleted so we don't lose focus
|
||||
next.setActive();
|
||||
|
||||
noteTree.setCurrentNotePathToHash(next);
|
||||
}
|
||||
|
||||
noteTree.setCurrentNotePathToHash(next);
|
||||
noteTree.reload();
|
||||
}
|
||||
|
||||
async function moveNodeUpInHierarchy(node) {
|
||||
if (node.getParent() === null) {
|
||||
if (isTopLevelNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await server.put('notes/' + node.data.note_tree_id + '/move-after/' + node.getParent().data.note_tree_id);
|
||||
|
||||
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
|
||||
if (!isTopLevelNode(node) && node.getParent().getChildren().length <= 1) {
|
||||
node.getParent().folder = false;
|
||||
node.getParent().renderTitle();
|
||||
}
|
||||
@ -98,11 +101,13 @@ const treeChanges = (function() {
|
||||
}
|
||||
|
||||
function changeNode(node, func) {
|
||||
assertArguments(node.data.parent_note_id, node.data.note_id);
|
||||
|
||||
noteTree.removeParentChildRelation(node.data.parent_note_id, node.data.note_id);
|
||||
|
||||
func(node);
|
||||
|
||||
node.data.parent_note_id = node.getParent() === null ? 'root' : node.getParent().data.note_id;
|
||||
node.data.parent_note_id = isTopLevelNode(node) ? 'root' : node.getParent().data.note_id;
|
||||
|
||||
noteTree.setParentChildRelation(node.data.note_tree_id, node.data.parent_note_id, node.data.note_id);
|
||||
|
||||
|
@ -4,7 +4,7 @@ const treeUtils = (function() {
|
||||
const treeEl = $("#tree");
|
||||
|
||||
function getParentProtectedStatus(node) {
|
||||
return node.getParent() === null ? 0 : node.getParent().data.is_protected;
|
||||
return isTopLevelNode(node) ? 0 : node.getParent().data.is_protected;
|
||||
}
|
||||
|
||||
function getNodeByKey(key) {
|
||||
@ -20,7 +20,7 @@ const treeUtils = (function() {
|
||||
function getNotePath(node) {
|
||||
const path = [];
|
||||
|
||||
while (node) {
|
||||
while (node && !isRootNode(node)) {
|
||||
if (node.data.note_id) {
|
||||
path.push(node.data.note_id);
|
||||
}
|
||||
|
@ -75,7 +75,9 @@ function isElectron() {
|
||||
|
||||
function assertArguments() {
|
||||
for (const i in arguments) {
|
||||
assert(arguments[i], `argument ${i} should not be falsy. Argument list: ${arguments}`);
|
||||
if (!arguments[i]) {
|
||||
throwError(`Argument idx#${i} should not be falsy: ${arguments[i]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,4 +85,12 @@ function assert(expr, message) {
|
||||
if (!expr) {
|
||||
throwError(message);
|
||||
}
|
||||
}
|
||||
|
||||
function isTopLevelNode(node) {
|
||||
return isRootNode(node.getParent());
|
||||
}
|
||||
|
||||
function isRootNode(node) {
|
||||
return node.key === "root_1";
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user