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:
+12
-27
@@ -1028,39 +1028,24 @@ export class WaypointView extends ItemView {
|
||||
const dragged = removeById(this.plugin.waypointData.bookmarks);
|
||||
if (!dragged) return;
|
||||
|
||||
// Find the target in its parent array
|
||||
const findTarget = (items: BookmarkItem[]): { parent: BookmarkItem[]; idx: number } | null => {
|
||||
const idx = items.findIndex(i => i.id === targetId);
|
||||
if (idx >= 0) return { parent: items, idx };
|
||||
for (const child of items) {
|
||||
if (child.children) {
|
||||
const result = findTarget(child.children);
|
||||
if (result) return result;
|
||||
// Find the target
|
||||
const findTarget = (items: BookmarkItem[]): BookmarkItem | null => {
|
||||
for (const item of items) {
|
||||
if (item.id === targetId) return item;
|
||||
if (item.children) {
|
||||
const found = findTarget(item.children);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const targetInfo = findTarget(this.plugin.waypointData.bookmarks);
|
||||
if (!targetInfo) return;
|
||||
const target = findTarget(this.plugin.waypointData.bookmarks);
|
||||
if (!target) return;
|
||||
|
||||
const target = targetInfo.parent[targetInfo.idx];
|
||||
const newGroup: BookmarkItem = {
|
||||
id: `bm-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
||||
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);
|
||||
// Make dragged item a child of the target
|
||||
dragged.indent = target.indent + 1;
|
||||
target.children.push(dragged);
|
||||
|
||||
this.plugin.saveWaypointData();
|
||||
this.redraw();
|
||||
|
||||
Reference in New Issue
Block a user