Skip to content

Commit 6dda8f2

Browse files
committed
feat: replace more options button with tabs right click handler
1 parent fd6086b commit 6dda8f2

File tree

6 files changed

+33
-70
lines changed

6 files changed

+33
-70
lines changed

src/extensionsIntegrated/TabBar/helper.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ define(function (require, exports, module) {
1010
/**
1111
* Shows the tab bar, when its hidden.
1212
* Its only shown when tab bar is enabled and there is atleast one working file
13-
* We need to show both the tab bar and the more options
1413
*
1514
* @param {$.Element} $tabBar - The tab bar element
1615
* @param {$.Element} $moreOptions - The more options element
1716
*/
1817
function _showTabBar($tabBar, $moreOptions) {
1918
if ($tabBar) {
2019
$tabBar.show();
21-
if($moreOptions) {
22-
$moreOptions.show();
23-
}
2420
// when we add/remove something from the editor, the editor shifts up/down which leads to blank space
2521
// so we need to recompute the layout to make sure things are in the right place
2622
WorkspaceManager.recomputeLayout(true);
@@ -30,17 +26,13 @@ define(function (require, exports, module) {
3026
/**
3127
* Hides the tab bar.
3228
* Its hidden when tab bar feature is disabled or there are no working files
33-
* Both the tab bar and the more options should be hidden to hide the tab bar container
3429
*
3530
* @param {$.Element} $tabBar - The tab bar element
3631
* @param {$.Element} $moreOptions - The more options element
3732
*/
3833
function _hideTabBar($tabBar, $moreOptions) {
3934
if ($tabBar) {
4035
$tabBar.hide();
41-
if($moreOptions) {
42-
$moreOptions.hide();
43-
}
4436
WorkspaceManager.recomputeLayout(true);
4537
}
4638
}

src/extensionsIntegrated/TabBar/html/tabbar-pane.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
<div id="phoenix-tab-bar" class="phoenix-tab-bar">
33

44
</div>
5-
<div id="tab-bar-more-options" class="tab-bar-more-options">
6-
<i class="fa-solid fa-ellipsis-vertical"></i>
7-
</div>
85
</div>

src/extensionsIntegrated/TabBar/html/tabbar-second-pane.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
<div id="phoenix-tab-bar-2" class="phoenix-tab-bar">
33

44
</div>
5-
<div id="tab-bar-more-options-2" class="tab-bar-more-options-2">
6-
<i class="fa-solid fa-ellipsis-vertical"></i>
7-
</div>
85
</div>

src/extensionsIntegrated/TabBar/main.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ define(function (require, exports, module) {
148148
const $secondTabBar = $('#phoenix-tab-bar-2');
149149

150150
if (Global.firstPaneWorkingSet.length === 0 && ($('#phoenix-tab-bar'))) {
151-
Helper._hideTabBar($('#phoenix-tab-bar'), $('#tab-bar-more-options'));
151+
Helper._hideTabBar($('#phoenix-tab-bar'));
152152
}
153153

154154
if (Global.secondPaneWorkingSet.length === 0 && ($('#phoenix-tab-bar-2'))) {
155-
Helper._hideTabBar($('#phoenix-tab-bar-2'), $('#tab-bar-more-options-2'));
155+
Helper._hideTabBar($('#phoenix-tab-bar-2'));
156156
}
157157

158158
// get the count of tabs that we want to display in the tab bar (from preference settings)
@@ -345,6 +345,19 @@ define(function (require, exports, module) {
345345
event.stopPropagation();
346346
}
347347
});
348+
349+
// Add contextmenu (right-click) handler
350+
$(document).on("contextmenu", ".tab", function (event) {
351+
event.preventDefault();
352+
event.stopPropagation();
353+
354+
// Determine which pane the tab belongs to
355+
const isSecondPane = $(this).closest("#phoenix-tab-bar-2").length > 0;
356+
const paneId = isSecondPane ? "second-pane" : "first-pane";
357+
358+
// Show context menu at mouse position
359+
MoreOptions.showMoreOptionsContextMenu(paneId, event.pageX, event.pageY);
360+
});
348361
}
349362

350363

@@ -397,16 +410,6 @@ define(function (require, exports, module) {
397410
}
398411
}
399412
});
400-
401-
// handle click events on the tab bar more options button
402-
$(document).on("click", ".tab-bar-more-options", function (event) {
403-
event.stopPropagation();
404-
MoreOptions.showMoreOptionsContextMenu("first-pane");
405-
});
406-
$(document).on("click", ".tab-bar-more-options-2", function (event) {
407-
event.stopPropagation();
408-
MoreOptions.showMoreOptionsContextMenu("second-pane");
409-
});
410413
}
411414

412415

src/extensionsIntegrated/TabBar/more-options.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,44 @@ define(function (require, exports, module) {
5151

5252

5353
/**
54-
* This function is called when the more options button is clicked
54+
* This function is called when a tab is right-clicked
5555
* This will show the more options context menu
56+
*
5657
* @param {String} paneId - the id of the pane ["first-pane", "second-pane"]
58+
* @param {Number} x - the x coordinate for positioning the menu
59+
* @param {Number} y - the y coordinate for positioning the menu
5760
*/
58-
function showMoreOptionsContextMenu(paneId) {
59-
61+
function showMoreOptionsContextMenu(paneId, x, y) {
6062
const dropdown = new DropdownButton.DropdownButton("", items);
6163

62-
// we need to determine which pane the tab belongs to show the context menu at the right place
63-
if (paneId === "first-pane") {
64-
$("#tab-bar-more-options").append(dropdown.$button);
65-
} else {
66-
$("#tab-bar-more-options-2").append(dropdown.$button);
67-
}
64+
// Append to document body for absolute positioning
65+
$("body").append(dropdown.$button);
66+
67+
// Position the dropdown at the mouse coordinates
68+
dropdown.$button.css({
69+
position: "absolute",
70+
left: x + "px",
71+
top: y + "px",
72+
zIndex: 1000
73+
});
6874

6975
dropdown.showDropdown();
7076

7177
// handle the option selection
7278
dropdown.on("select", function (e, item, index) {
7379
if (index === 0) {
7480
handleCloseAllTabs();
75-
} else if(index === 1) {
81+
} else if (index === 1) {
7682
handleCloseUnmodifiedTabs();
77-
} else if(index === 2) {
83+
} else if (index === 2) {
7884
reopenClosedFile();
7985
}
8086
});
8187

88+
// Remove the button after the dropdown is hidden
8289
dropdown.$button.css({
8390
display: "none"
8491
});
85-
8692
}
8793

8894
module.exports = {

src/styles/Extn-TabBar.less

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,6 @@
2626
}
2727

2828

29-
.tab-bar-more-options,
30-
.tab-bar-more-options-2 {
31-
display: flex;
32-
align-items: center;
33-
height: 2rem;
34-
padding: 0 0.5rem;
35-
cursor: pointer;
36-
position: relative;
37-
z-index: 2;
38-
margin-left: auto;
39-
}
40-
41-
42-
.tab-bar-more-options:hover,
43-
.tab-bar-more-options-2:hover {
44-
background-color: #333;
45-
}
46-
47-
48-
.tab-bar-more-options::before,
49-
.tab-bar-more-options-2::before {
50-
content: "";
51-
position: absolute;
52-
top: 0;
53-
left: -1rem;
54-
width: 1rem;
55-
height: 100%;
56-
pointer-events: none;
57-
background: linear-gradient(to right, rgba(30, 30, 30, 0), #1E1E1E);
58-
}
59-
60-
6129
.tab {
6230
display: inline-flex;
6331
align-items: center;

0 commit comments

Comments
 (0)