mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes to stable sorting
This commit is contained in:
parent
45ed436426
commit
f37f47ce5b
@ -756,7 +756,7 @@ class BNote extends AbstractBeccaEntity {
|
|||||||
} else if (a.parentNote?.isHiddenCompletely()) {
|
} else if (a.parentNote?.isHiddenCompletely()) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -776,7 +776,7 @@ class BNote extends AbstractBeccaEntity {
|
|||||||
const aBranch = becca.getBranchFromChildAndParent(a.noteId, this.noteId);
|
const aBranch = becca.getBranchFromChildAndParent(a.noteId, this.noteId);
|
||||||
const bBranch = becca.getBranchFromChildAndParent(b.noteId, this.noteId);
|
const bBranch = becca.getBranchFromChildAndParent(b.noteId, this.noteId);
|
||||||
|
|
||||||
return aBranch?.notePosition < bBranch?.notePosition ? -1 : 1;
|
return (aBranch?.notePosition - bBranch?.notePosition) || 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ function register(router) {
|
|||||||
zipImportService.importZip(taskContext, req.body, note).then(importedNote => {
|
zipImportService.importZip(taskContext, req.body, note).then(importedNote => {
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
note: mappers.mapNoteToPojo(importedNote),
|
note: mappers.mapNoteToPojo(importedNote),
|
||||||
branch: mappers.mapBranchToPojo(importedNote.getBranches()[0]),
|
branch: mappers.mapBranchToPojo(importedNote.getParentBranches()[0]),
|
||||||
});
|
});
|
||||||
}); // we need better error handling here, async errors won't be properly processed.
|
}); // we need better error handling here, async errors won't be properly processed.
|
||||||
});
|
});
|
||||||
|
@ -130,7 +130,7 @@ class FNote {
|
|||||||
branchIdPos[branchId] = this.froca.getBranch(branchId).notePosition;
|
branchIdPos[branchId] = this.froca.getBranch(branchId).notePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.children.sort((a, b) => branchIdPos[this.childToBranch[a]] < branchIdPos[this.childToBranch[b]] ? -1 : 1);
|
this.children.sort((a, b) => branchIdPos[this.childToBranch[a]] - branchIdPos[this.childToBranch[b]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {boolean} */
|
/** @returns {boolean} */
|
||||||
@ -228,7 +228,7 @@ class FNote {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
async renderOwnedAttributes(ownedAttributes, saved) {
|
async renderOwnedAttributes(ownedAttributes, saved) {
|
||||||
// attrs are not resorted if position changes after the initial load
|
// attrs are not resorted if position changes after the initial load
|
||||||
ownedAttributes.sort((a, b) => a.position < b.position ? -1 : 1);
|
ownedAttributes.sort((a, b) => a.position - b.position);
|
||||||
|
|
||||||
let htmlAttrs = (await attributeRenderer.renderAttributes(ownedAttributes, true)).html();
|
let htmlAttrs = (await attributeRenderer.renderAttributes(ownedAttributes, true)).html();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class BasicWidget extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.children.sort((a, b) => a.position - b.position < 0 ? -1 : 1);
|
this.children.sort((a, b) => a.position - b.position);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1147,7 +1147,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
let parentsOfAddedNodes = [];
|
let parentsOfAddedNodes = [];
|
||||||
|
|
||||||
const allBranchRows = loadResults.getBranchRows();
|
const allBranchRows = loadResults.getBranchRows();
|
||||||
// TODO: this flag is suspicious - why does it matter that all branches in a particular update are deleted?
|
|
||||||
const allBranchesDeleted = allBranchRows.every(branchRow => !!branchRow.isDeleted);
|
const allBranchesDeleted = allBranchRows.every(branchRow => !!branchRow.isDeleted);
|
||||||
|
|
||||||
for (const branchRow of allBranchRows) {
|
for (const branchRow of allBranchRows) {
|
||||||
@ -1190,12 +1189,16 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const found = (parentNode.getChildren() || []).find(child => child.data.noteId === branchRow.noteId);
|
|
||||||
if (!found) {
|
|
||||||
// make sure it's loaded
|
|
||||||
const note = await froca.getNote(branchRow.noteId);
|
const note = await froca.getNote(branchRow.noteId);
|
||||||
const frocaBranch = froca.getBranch(branchRow.branchId);
|
const frocaBranch = froca.getBranch(branchRow.branchId);
|
||||||
|
const foundNode = (parentNode.getChildren() || []).find(child => child.data.noteId === branchRow.noteId);
|
||||||
|
if (foundNode) {
|
||||||
|
// the branch already exists in the tree
|
||||||
|
if (branchRow.isExpanded !== foundNode.isExpanded()) {
|
||||||
|
noteIdsToReload.add(frocaBranch.noteId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// make sure it's loaded
|
||||||
// we're forcing lazy since it's not clear if the whole required subtree is in froca
|
// we're forcing lazy since it's not clear if the whole required subtree is in froca
|
||||||
parentNode.addChildren([this.prepareNode(frocaBranch, true)]);
|
parentNode.addChildren([this.prepareNode(frocaBranch, true)]);
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
attrs.sort((a, b) => {
|
attrs.sort((a, b) => {
|
||||||
if (a.noteId === b.noteId) {
|
if (a.noteId === b.noteId) {
|
||||||
return a.position < b.position ? -1 : 1;
|
return a.position - b.position;
|
||||||
} else {
|
} else {
|
||||||
// inherited attributes should stay grouped: https://github.com/zadam/trilium/issues/3761
|
// inherited attributes should stay grouped: https://github.com/zadam/trilium/issues/3761
|
||||||
return a.noteId < b.noteId ? -1 : 1;
|
return a.noteId < b.noteId ? -1 : 1;
|
||||||
|
@ -83,7 +83,7 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
// attrs are not resorted if position changes after the initial load
|
// attrs are not resorted if position changes after the initial load
|
||||||
// promoted attrs are sorted primarily by order of definitions, but with multi-valued promoted attrs
|
// promoted attrs are sorted primarily by order of definitions, but with multi-valued promoted attrs
|
||||||
// the order of attributes is important as well
|
// the order of attributes is important as well
|
||||||
ownedAttributes.sort((a, b) => a.position < b.position ? -1 : 1);
|
ownedAttributes.sort((a, b) => a.position - b.position);
|
||||||
|
|
||||||
if (promotedDefAttrs.length === 0) {
|
if (promotedDefAttrs.length === 0) {
|
||||||
this.toggleInt(false);
|
this.toggleInt(false);
|
||||||
|
@ -20,7 +20,7 @@ const markdownService = require("./markdown");
|
|||||||
* @param {TaskContext} taskContext
|
* @param {TaskContext} taskContext
|
||||||
* @param {Buffer} fileBuffer
|
* @param {Buffer} fileBuffer
|
||||||
* @param {BNote} importRootNote
|
* @param {BNote} importRootNote
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<BNote>}
|
||||||
*/
|
*/
|
||||||
async function importZip(taskContext, fileBuffer, importRootNote) {
|
async function importZip(taskContext, fileBuffer, importRootNote) {
|
||||||
/** @type {Object.<string, string>} maps from original noteId (in ZIP file) to newly generated noteId */
|
/** @type {Object.<string, string>} maps from original noteId (in ZIP file) to newly generated noteId */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user