mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fixes to stable sorting
This commit is contained in:
		| @@ -756,7 +756,7 @@ class BNote extends AbstractBeccaEntity { | ||||
|             } else if (a.parentNote?.isHiddenCompletely()) { | ||||
|                 return 1; | ||||
|             } else { | ||||
|                 return -1; | ||||
|                 return 0; | ||||
|             } | ||||
|         }); | ||||
|  | ||||
| @@ -776,7 +776,7 @@ class BNote extends AbstractBeccaEntity { | ||||
|             const aBranch = becca.getBranchFromChildAndParent(a.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 => { | ||||
|             res.status(201).json({ | ||||
|                 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. | ||||
|     }); | ||||
|   | ||||
| @@ -130,7 +130,7 @@ class FNote { | ||||
|             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} */ | ||||
| @@ -228,7 +228,7 @@ class FNote { | ||||
|                 return 1; | ||||
|             } | ||||
|  | ||||
|             return -1; | ||||
|             return 0; | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -473,7 +473,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget { | ||||
|  | ||||
|     async renderOwnedAttributes(ownedAttributes, saved) { | ||||
|         // 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(); | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
|   | ||||
| @@ -1147,7 +1147,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|         let parentsOfAddedNodes = []; | ||||
|  | ||||
|         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); | ||||
|  | ||||
|         for (const branchRow of allBranchRows) { | ||||
| @@ -1190,12 +1189,16 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|                         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 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 | ||||
|                         parentNode.addChildren([this.prepareNode(frocaBranch, true)]); | ||||
|  | ||||
|   | ||||
| @@ -96,7 +96,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { | ||||
|  | ||||
|         attrs.sort((a, b) => { | ||||
|             if (a.noteId === b.noteId) { | ||||
|                 return a.position < b.position ? -1 : 1; | ||||
|                 return a.position - b.position; | ||||
|             } else { | ||||
|                 // inherited attributes should stay grouped: https://github.com/zadam/trilium/issues/3761 | ||||
|                 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 | ||||
|         // promoted attrs are sorted primarily by order of definitions, but with multi-valued promoted attrs | ||||
|         // 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) { | ||||
|             this.toggleInt(false); | ||||
|   | ||||
| @@ -20,7 +20,7 @@ const markdownService = require("./markdown"); | ||||
|  * @param {TaskContext} taskContext | ||||
|  * @param {Buffer} fileBuffer | ||||
|  * @param {BNote} importRootNote | ||||
|  * @returns {Promise<*>} | ||||
|  * @returns {Promise<BNote>} | ||||
|  */ | ||||
| async function importZip(taskContext, fileBuffer, importRootNote) { | ||||
|     /** @type {Object.<string, string>} maps from original noteId (in ZIP file) to newly generated noteId */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user