Skip to content

Commit 6a6ce5f

Browse files
authored
fix: Check file path as well when moving (#653)
Signed-off-by: sheche <[email protected]>
1 parent 2d7c099 commit 6a6ce5f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/views/DragAndDropController.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ export class DragAndDropController implements TreeDragAndDropController<Explorer
145145
return;
146146
}
147147

148-
// check if the target node is source node itself or its parent.
149-
if (target?.isItselfOrAncestorOf(source, 1 /*levelToCheck*/)) {
148+
if (this.isTheSameOrParent(target!, source!)) {
150149
return;
151150
}
152151

@@ -313,6 +312,25 @@ export class DragAndDropController implements TreeDragAndDropController<Explorer
313312
return false;
314313
}
315314

315+
/**
316+
* Check whether the target node is the same or parent of the source node.
317+
* If the target node's file path is parent of the source node's, `true`
318+
* well be returned as well.
319+
*/
320+
private isTheSameOrParent(target: ExplorerNode, source: DataNode): boolean {
321+
if (target.isItselfOrAncestorOf(source, 1 /*levelToCheck*/)) {
322+
return true;
323+
}
324+
325+
if ((target instanceof DataNode) && target.uri && source.uri) {
326+
const targetPath = Uri.parse(target.uri).fsPath;
327+
const sourcePath = Uri.parse(source.uri).fsPath;
328+
return path.relative(sourcePath, targetPath) === "..";
329+
}
330+
331+
return false;
332+
}
333+
316334
/**
317335
* Trigger a workspace edit that move the source node into the target node.
318336
*/

0 commit comments

Comments
 (0)