Skip to content

Commit b7a0754

Browse files
devvaannshabose
authored andcommitted
fix: mousedown event not getting trigged when dropdown exists, moved everything to click handler
1 parent 8de275f commit b7a0754

File tree

1 file changed

+16
-40
lines changed
  • src/extensionsIntegrated/TabBar

1 file changed

+16
-40
lines changed

src/extensionsIntegrated/TabBar/main.js

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -487,60 +487,36 @@ define(function (require, exports, module) {
487487
function handleTabClick() {
488488
// delegate event handling for both tab bars
489489
$(document).on("click", ".phoenix-tab-bar .tab", function (event) {
490-
// check if the clicked element is the close button
491-
if ($(event.target).hasClass("fa-times") || $(event.target).closest(".tab-close").length) {
492-
// Get the file path from the data-path attribute of the parent tab
493-
const filePath = $(this).attr("data-path");
494-
495-
if (filePath) {
496-
// determine the pane inside which the tab belongs
497-
const isSecondPane = $(this).closest("#phoenix-tab-bar-2").length > 0;
498-
const paneId = isSecondPane ? "second-pane" : "first-pane";
499-
500-
// get the file object
501-
const fileObj = FileSystem.getFileForPath(filePath);
502-
// close the file
503-
CommandManager.execute(Commands.FILE_CLOSE, { file: fileObj, paneId: paneId });
490+
// Get the file path from the data-path attribute of the parent tab
491+
const filePath = $(this).attr("data-path");
492+
if (!filePath) { return; }
504493

505-
// Prevent default behavior
506-
event.preventDefault();
507-
event.stopPropagation();
508-
}
509-
}
510-
});
494+
// determine the pane inside which the tab belongs
495+
const isSecondPane = $(this).closest("#phoenix-tab-bar-2").length > 0;
496+
const paneId = isSecondPane ? "second-pane" : "first-pane";
511497

512-
// delegate event handling for both tab bars
513-
$(document).on("mousedown", ".phoenix-tab-bar .tab", function (event) {
514-
// to prevent right-clicks from activating the mousedown event
515-
if (event.button === 2) { return; }
498+
// get the file object
499+
const fileObj = FileSystem.getFileForPath(filePath);
516500

501+
// check if the clicked element is the close button
517502
if ($(event.target).hasClass("fa-times") || $(event.target).closest(".tab-close").length) {
518-
return;
519-
}
520-
// Get the file path from the data-path attribute
521-
const filePath = $(this).attr("data-path");
503+
event.preventDefault();
504+
event.stopPropagation();
522505

523-
if (filePath) {
524-
// determine the pane inside which the tab belongs
525-
const isSecondPane = $(this).closest("#phoenix-tab-bar-2").length > 0;
526-
const paneId = isSecondPane ? "second-pane" : "first-pane";
506+
CommandManager.execute(Commands.FILE_CLOSE, { file: fileObj, paneId: paneId }); // close the file
507+
} else { // open the clicked tab
527508
const currentActivePane = MainViewManager.getActivePaneId();
528509
const isPaneActive = paneId === currentActivePane;
529510
const currentFile = MainViewManager.getCurrentlyViewedFile(currentActivePane);
530511

531-
// Check if this is a placeholder tab
512+
// if the clicked tab is a placeholder tab, we add it to the working set
532513
if ($(this).hasClass("placeholder")) {
533-
// Add the file to the working set when placeholder tab is clicked
534-
const fileObj = FileSystem.getFileForPath(filePath);
535514
MainViewManager.addToWorkingSet(paneId, fileObj);
536515
}
537516

538-
if (isPaneActive && currentFile && currentFile.fullPath === filePath) {
539-
return;
540-
}
517+
// clicked tab is already active, don't do anything
518+
if (isPaneActive && currentFile && currentFile.fullPath === filePath) { return; }
541519
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filePath, paneId: paneId });
542-
543-
// We dont prevent default behavior here to enable drag and drop of this tab
544520
}
545521
});
546522

0 commit comments

Comments
 (0)