Skip to content

Commit d56266a

Browse files
devvaannshabose
authored andcommitted
refactor: use mousedown to switch tabs instead of click
1 parent de2bef5 commit d56266a

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/extensionsIntegrated/TabBar/main.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -507,20 +507,37 @@ define(function (require, exports, module) {
507507
event.stopPropagation();
508508

509509
CommandManager.execute(Commands.FILE_CLOSE, { file: fileObj, paneId: paneId }); // close the file
510-
} else { // open the clicked tab
511-
const currentActivePane = MainViewManager.getActivePaneId();
512-
const isPaneActive = paneId === currentActivePane;
513-
const currentFile = MainViewManager.getCurrentlyViewedFile(currentActivePane);
514-
515-
// if the clicked tab is a placeholder tab, we add it to the working set
516-
if ($(this).hasClass("placeholder")) {
517-
MainViewManager.addToWorkingSet(paneId, fileObj);
518-
}
510+
}
511+
});
519512

520-
// clicked tab is already active, don't do anything
521-
if (isPaneActive && currentFile && currentFile.fullPath === filePath) { return; }
522-
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filePath, paneId: paneId });
513+
// open tab on mousedown event
514+
$(document).on("mousedown", ".phoenix-tab-bar .tab", function (event) {
515+
if ($(event.target).hasClass("fa-times") || $(event.target).closest(".tab-close").length) {
516+
return;
523517
}
518+
519+
// Get the file path from the data-path attribute of the parent tab
520+
const filePath = $(this).attr("data-path");
521+
if (!filePath) { return; }
522+
523+
// determine the pane inside which the tab belongs
524+
const isSecondPane = $(this).closest("#phoenix-tab-bar-2").length > 0;
525+
const paneId = isSecondPane ? "second-pane" : "first-pane";
526+
527+
// get the file object
528+
const fileObj = FileSystem.getFileForPath(filePath);
529+
const currentActivePane = MainViewManager.getActivePaneId();
530+
const isPaneActive = paneId === currentActivePane;
531+
const currentFile = MainViewManager.getCurrentlyViewedFile(currentActivePane);
532+
533+
// if the clicked tab is a placeholder tab, we add it to the working set
534+
if ($(this).hasClass("placeholder")) {
535+
MainViewManager.addToWorkingSet(paneId, fileObj);
536+
}
537+
538+
// clicked tab is already active, don't do anything
539+
if (isPaneActive && currentFile && currentFile.fullPath === filePath) { return; }
540+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filePath, paneId: paneId });
524541
});
525542

526543
// Add the contextmenu (right-click) handler

test/spec/Extn-Tabbar-integ-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ define(function (require, exports, module) {
11931193
async function clickTabAndVerify(filePath, description) {
11941194
const $tab = getTab(filePath);
11951195
expect($tab.length).toBe(1);
1196-
$tab.trigger("click");
1196+
$tab.trigger("mousedown");
11971197

11981198
// Wait for the file to become active
11991199
await awaitsFor(

0 commit comments

Comments
 (0)