fix: drag onto file makes dragged item a child of that file

Dragging B onto A:
  ▶ File A
      File B

A becomes the parent, B becomes its child. No new group created.
This commit is contained in:
2026-06-12 14:52:04 -04:00
parent 7331a455ad
commit e0c3deee86
2 changed files with 18 additions and 33 deletions
+6 -6
View File
File diff suppressed because one or more lines are too long
+12 -27
View File
@@ -1028,39 +1028,24 @@ export class WaypointView extends ItemView {
const dragged = removeById(this.plugin.waypointData.bookmarks); const dragged = removeById(this.plugin.waypointData.bookmarks);
if (!dragged) return; if (!dragged) return;
// Find the target in its parent array // Find the target
const findTarget = (items: BookmarkItem[]): { parent: BookmarkItem[]; idx: number } | null => { const findTarget = (items: BookmarkItem[]): BookmarkItem | null => {
const idx = items.findIndex(i => i.id === targetId); for (const item of items) {
if (idx >= 0) return { parent: items, idx }; if (item.id === targetId) return item;
for (const child of items) { if (item.children) {
if (child.children) { const found = findTarget(item.children);
const result = findTarget(child.children); if (found) return found;
if (result) return result;
} }
} }
return null; return null;
}; };
const targetInfo = findTarget(this.plugin.waypointData.bookmarks); const target = findTarget(this.plugin.waypointData.bookmarks);
if (!targetInfo) return; if (!target) return;
const target = targetInfo.parent[targetInfo.idx]; // Make dragged item a child of the target
const newGroup: BookmarkItem = { dragged.indent = target.indent + 1;
id: `bm-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`, target.children.push(dragged);
type: 'group',
label: 'New Group',
filePath: '',
icon: '',
children: [
{ ...target, indent: target.indent + 1 },
{ ...dragged, indent: target.indent + 1 },
],
collapsed: false,
indent: target.indent,
};
// Replace target with the new group
targetInfo.parent.splice(targetInfo.idx, 1, newGroup);
this.plugin.saveWaypointData(); this.plugin.saveWaypointData();
this.redraw(); this.redraw();