fix(hidden_subtree): launcher branches created both in visible & available (closes #6537)

This commit is contained in:
Elian Doran 2025-08-03 11:12:21 +03:00
parent 384ab1d1f3
commit 425ade5212
No known key found for this signature in database
2 changed files with 30 additions and 11 deletions

View File

@ -83,6 +83,23 @@ describe("Hidden Subtree", () => {
expect(updatedJumpToNote?.title).not.toBe("Renamed");
});
it("maintains launchers hidden, if they were shown by default but moved by the user", () => {
const launcher = becca.getNote("_lbLlmChat");
const branch = launcher?.getParentBranches()[0];
expect(branch).toBeDefined();
expect(branch!.parentNoteId).toBe("_lbVisibleLaunchers");
expect(launcher).toBeDefined();
cls.init(() => {
branches.moveBranchToNote(branch!, "_lbAvailableLaunchers");
hiddenSubtreeService.checkHiddenSubtree();
});
const newBranches = launcher?.getParentBranches().filter(b => !b.isDeleted);
expect(newBranches).toHaveLength(1);
expect(newBranches![0].parentNoteId).toBe("_lbAvailableLaunchers");
});
it("can restore names in all languages", async () => {
const done = deferred<void>();
cls.wrap(async () => {

View File

@ -356,20 +356,22 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: HiddenSubtree
} else {
branch = note.getParentBranches().find((branch) => branch.parentNoteId === parentNoteId);
// If the note exists but doesn't have a branch in the expected parent,
// create the missing branch to ensure it's in the correct location
if (!branch) {
branch = new BBranch({
noteId: item.id,
parentNoteId: parentNoteId,
notePosition: item.notePosition !== undefined ? item.notePosition : undefined,
isExpanded: item.isExpanded !== undefined ? item.isExpanded : false
}).save();
}
// Clean up any branches that shouldn't exist according to the meta definition
// For hidden subtree notes, we want to ensure they only exist in their designated locations
if (item.enforceBranches || item.id.startsWith("_help")) {
// If the note exists but doesn't have a branch in the expected parent,
// create the missing branch to ensure it's in the correct location
if (!branch) {
console.log("Creating missing branch for note", item.id, "under parent", parentNoteId);
branch = new BBranch({
noteId: item.id,
parentNoteId: parentNoteId,
notePosition: item.notePosition !== undefined ? item.notePosition : undefined,
isExpanded: item.isExpanded !== undefined ? item.isExpanded : false
}).save();
}
// Remove any branches that are not in the expected parent.
const expectedParents = getExpectedParentIds(item.id, hiddenSubtreeDefinition);
const currentBranches = note.getParentBranches();