Skip to content

Commit cee53fc

Browse files
committed
fix: unable to drag and drop tabs over the editor area
1 parent 2f607eb commit cee53fc

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

docs/API-Reference/command/Commands.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,18 @@ Sorts working set by file type
824824
## CMD\_WORKING\_SORT\_TOGGLE\_AUTO
825825
Toggles automatic working set sorting
826826

827+
**Kind**: global variable
828+
<a name="CMD_TOGGLE_SHOW_WORKING_SET"></a>
829+
830+
## CMD\_TOGGLE\_SHOW\_WORKING\_SET
831+
Toggles working set visibility
832+
833+
**Kind**: global variable
834+
<a name="CMD_TOGGLE_SHOW_FILE_TABS"></a>
835+
836+
## CMD\_TOGGLE\_SHOW\_FILE\_TABS
837+
Toggles file tabs visibility
838+
827839
**Kind**: global variable
828840
<a name="CMD_TOGGLE_SHOW_WORKING_SET"></a>
829841

src/extensionsIntegrated/TabBar/drag-drop.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,7 @@ define(function (require, exports, module) {
671671

672672
// Handle drag over empty pane
673673
$paneHolder.on("dragover dragenter", function (e) {
674-
// we only want to process if this pane is empty (has no tab bar or has hidden tab bar)
675-
const $tabBar = paneId === "first-pane" ? $("#phoenix-tab-bar") : $("#phoenix-tab-bar-2");
676-
const isEmptyPane = !$tabBar.length || $tabBar.is(":hidden") || $tabBar.children(".tab").length === 0;
677-
678-
if (isEmptyPane && draggedTab) {
674+
if (draggedTab) {
679675
e.preventDefault();
680676
e.stopPropagation();
681677

@@ -697,7 +693,7 @@ define(function (require, exports, module) {
697693
const $tabBar = paneId === "first-pane" ? $("#phoenix-tab-bar") : $("#phoenix-tab-bar-2");
698694
const isEmptyPane = !$tabBar.length || $tabBar.is(":hidden") || $tabBar.children(".tab").length === 0;
699695

700-
if (isEmptyPane && draggedTab) {
696+
if (draggedTab) {
701697
e.preventDefault();
702698
e.stopPropagation();
703699

@@ -711,9 +707,11 @@ define(function (require, exports, module) {
711707
const sourcePaneId =
712708
$(draggedTab).closest("#phoenix-tab-bar-2").length > 0 ? "second-pane" : "first-pane";
713709

714-
// we don't want to do anything if dropping in the same pane
715-
if (sourcePaneId !== paneId) {
710+
// we only want to proceed if we're not dropping in the same pane or,
711+
// allow if it's the same pane with existing tabs
712+
if (sourcePaneId !== paneId || !isEmptyPane) {
716713
const sourceWorkingSet = MainViewManager.getWorkingSet(sourcePaneId);
714+
const targetWorkingSet = MainViewManager.getWorkingSet(paneId);
717715
let draggedFile = null;
718716

719717
// Find the dragged file in the source pane
@@ -725,12 +723,47 @@ define(function (require, exports, module) {
725723
}
726724

727725
if (draggedFile) {
728-
// close in the source pane
729-
CommandManager.execute(Commands.FILE_CLOSE, { file: draggedFile, paneId: sourcePaneId });
730-
731-
// and open in the target pane
732-
MainViewManager.addToWorkingSet(paneId, draggedFile);
733-
CommandManager.execute(Commands.FILE_OPEN, { fullPath: draggedPath, paneId: paneId });
726+
if (sourcePaneId !== paneId) {
727+
// If different panes, close in source pane
728+
CommandManager.execute(Commands.FILE_CLOSE, { file: draggedFile, paneId: sourcePaneId });
729+
730+
// For non-empty panes, find current active file to place tab after it
731+
if (!isEmptyPane && targetWorkingSet.length > 0) {
732+
const currentActiveFile = MainViewManager.getCurrentlyViewedFile(paneId);
733+
734+
if (currentActiveFile) {
735+
// Find index of current active file
736+
let targetIndex = -1;
737+
for (let i = 0; i < targetWorkingSet.length; i++) {
738+
if (targetWorkingSet[i].fullPath === currentActiveFile.fullPath) {
739+
targetIndex = i;
740+
break;
741+
}
742+
}
743+
744+
if (targetIndex !== -1) {
745+
// Add after current active file
746+
MainViewManager.addToWorkingSet(paneId, draggedFile, targetIndex + 1);
747+
} else {
748+
// Fallback to adding at the end
749+
MainViewManager.addToWorkingSet(paneId, draggedFile);
750+
}
751+
} else {
752+
// No active file, add to the end
753+
MainViewManager.addToWorkingSet(paneId, draggedFile);
754+
}
755+
} else {
756+
// Empty pane, just add it
757+
MainViewManager.addToWorkingSet(paneId, draggedFile);
758+
}
759+
760+
// Open file in target pane
761+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: draggedPath, paneId: paneId });
762+
} else if (isEmptyPane) {
763+
// Same pane, empty pane case (should never happen but kept for safety)
764+
MainViewManager.addToWorkingSet(paneId, draggedFile);
765+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: draggedPath, paneId: paneId });
766+
}
734767
}
735768
}
736769

0 commit comments

Comments
 (0)