Skip to content

Commit 9375dd9

Browse files
devvaannshabose
authored andcommitted
feat: add close button in overflow menu to work
1 parent 4942060 commit 9375dd9

File tree

3 files changed

+79
-18
lines changed

3 files changed

+79
-18
lines changed

src/extensionsIntegrated/TabBar/main.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ define(function (require, exports, module) {
191191
displayedEntries.forEach(function (entry) {
192192
$firstTabBar.append(createTab(entry));
193193
Overflow.toggleOverflowVisibility("first-pane");
194-
Overflow.scrollToActiveTab($firstTabBar);
194+
setTimeout(function () {
195+
Overflow.scrollToActiveTab($firstTabBar);
196+
}, 0);
195197
});
196198
}
197199

@@ -209,7 +211,9 @@ define(function (require, exports, module) {
209211
displayedEntries2.forEach(function (entry) {
210212
$secondTabBar.append(createTab(entry));
211213
Overflow.toggleOverflowVisibility("second-pane");
212-
Overflow.scrollToActiveTab($firstTabBar);
214+
setTimeout(function () {
215+
Overflow.scrollToActiveTab($secondTabBar);
216+
}, 0);
213217
});
214218
}
215219
}
@@ -341,12 +345,16 @@ define(function (require, exports, module) {
341345
// Now that tabs are updated, scroll to the active tab if necessary.
342346
if ($firstTabBar.length) {
343347
Overflow.toggleOverflowVisibility("first-pane");
344-
Overflow.scrollToActiveTab($firstTabBar);
348+
setTimeout(function () {
349+
Overflow.scrollToActiveTab($firstTabBar);
350+
}, 0);
345351
}
346352

347353
if ($secondTabBar.length) {
348354
Overflow.toggleOverflowVisibility("second-pane");
349-
Overflow.scrollToActiveTab($secondTabBar);
355+
setTimeout(function () {
356+
Overflow.scrollToActiveTab($secondTabBar);
357+
}, 0);
350358
}
351359
}
352360

@@ -449,13 +457,28 @@ define(function (require, exports, module) {
449457
EditorManager.on("activeEditorChange", updateTabs);
450458

451459
// For working set changes, update only the tabs.
460+
MainViewManager.off("workingSetAdd", updateTabs);
452461
MainViewManager.on("workingSetAdd", updateTabs);
462+
463+
MainViewManager.off("workingSetRemove", updateTabs);
453464
MainViewManager.on("workingSetRemove", updateTabs);
465+
466+
MainViewManager.off("workingSetSort", updateTabs);
454467
MainViewManager.on("workingSetSort", updateTabs);
468+
469+
MainViewManager.off("workingSetMove", updateTabs);
455470
MainViewManager.on("workingSetMove", updateTabs);
471+
472+
MainViewManager.off("workingSetAddList", updateTabs);
456473
MainViewManager.on("workingSetAddList", updateTabs);
474+
475+
MainViewManager.off("workingSetRemoveList", updateTabs);
457476
MainViewManager.on("workingSetRemoveList", updateTabs);
477+
478+
MainViewManager.off("workingSetUpdate", updateTabs);
458479
MainViewManager.on("workingSetUpdate", updateTabs);
480+
481+
MainViewManager.off("_workingSetDisableAutoSort", updateTabs);
459482
MainViewManager.on("_workingSetDisableAutoSort", updateTabs);
460483

461484
// file dirty flag change remains unchanged.

src/extensionsIntegrated/TabBar/overflow.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define(function (require, exports, module) {
66
const CommandManager = require("command/CommandManager");
77
const Commands = require("command/Commands");
88
const EditorManager = require("editor/EditorManager");
9+
const FileSystem = require("filesystem/FileSystem");
910

1011

1112
/**
@@ -104,6 +105,10 @@ define(function (require, exports, module) {
104105
// first, remove any existing dropdown menus to prevent duplicates
105106
$(".dropdown-overflow-menu").remove();
106107

108+
// Create a map to track tabs that are being closed
109+
// Using paths as keys for quick lookup
110+
const closingTabPaths = {};
111+
107112
// create the dropdown
108113
const dropdown = new DropdownButton.DropdownButton("", hiddenTabs, function (item, index) {
109114
const iconHtml = item.$icon[0].outerHTML; // the file icon
@@ -112,9 +117,9 @@ define(function (require, exports, module) {
112117
: ''; // to display the dirty icon in the overflow menu
113118

114119
const closeIconHtml =
115-
`<span class="tab-close-icon-overflow" data-tab-path="${item.path}">
116-
&times;
117-
</span>`;
120+
`<span class="tab-close-icon-overflow" data-tab-path="${item.path}" data-tab-index="${index}">
121+
<i class="fa-solid fa-times"></i>
122+
</span>`;
118123

119124
// return html for this item
120125
return {
@@ -129,7 +134,7 @@ define(function (require, exports, module) {
129134
};
130135
});
131136

132-
// add the custom classes for stlying the dropdown
137+
// add the custom classes for styling the dropdown
133138
dropdown.dropdownExtraClasses = "dropdown-overflow-menu";
134139
dropdown.$button.addClass("btn-overflow-tabs");
135140

@@ -144,12 +149,46 @@ define(function (require, exports, module) {
144149
zIndex: 1000
145150
});
146151

147-
// not sure why we need this but without it, the dropdown doesn't work
152+
153+
// custom handler for close button clicks - must be set up BEFORE showing dropdown
154+
// using one because we only want to run this handler once
155+
$(document).one("mousedown", ".tab-close-icon-overflow", function (e) {
156+
// store the path of the tab being closed
157+
const tabPath = $(this).data("tab-path");
158+
closingTabPaths[tabPath] = true;
159+
160+
// we don't stop propagation here - let the event bubble up
161+
// because we want the tab click handler to run as we are not closing the tab here
162+
// Why all this is done instead of simply closing the tab?
163+
// There was no way to stop the tab click handler from running.
164+
// Tried propagating the event, and all other stuff but that didn't work.
165+
// So what used to happen was that the tab used to get closed but then appeared again
166+
167+
// But we do prevent the default action
168+
e.preventDefault();
169+
});
170+
148171
dropdown.showDropdown();
149172

150173
// handle the option selection
151-
// the file that is selected will be opened
152174
dropdown.on("select", function (e, item, index) {
175+
// check if this tab was marked for closing
176+
if (closingTabPaths[item.path]) {
177+
// this tab is being closed, so handle the close operation
178+
const file = FileSystem.getFileForPath(item.path);
179+
180+
if (file) {
181+
// use setTimeout to ensure this happens after all event handlers
182+
setTimeout(function () {
183+
CommandManager.execute(Commands.FILE_CLOSE, { file: file, paneId: paneId });
184+
// clean up
185+
delete closingTabPaths[item.path];
186+
}, 0);
187+
}
188+
189+
return false;
190+
}
191+
// regular tab selection - open the file
153192
const filePath = item.path;
154193
if (filePath) {
155194
// Set the active pane and open the file
@@ -160,7 +199,7 @@ define(function (require, exports, module) {
160199

161200
// clean up when the dropdown is closed
162201
dropdown.$button.on("dropdown-closed", function () {
163-
$(document).off("click", ".tab-close-icon-overflow");
202+
$(document).off("mousedown", ".tab-close-icon-overflow");
164203
dropdown.$button.remove();
165204
});
166205

@@ -208,12 +247,12 @@ define(function (require, exports, module) {
208247
// get the current scroll position
209248
const currentScroll = $tabBarElement.scrollLeft();
210249

211-
// Check if the active tab is fully visible
250+
// Adjust scroll position if the tab is off-screen
212251
if (tabLeftRelative < 0) {
213-
// tab is scrolled too far to the left
252+
// tab is too far to the left
214253
$tabBarElement.scrollLeft(currentScroll + tabLeftRelative - 10); // 10px padding
215254
} else if (tabRightRelative > tabBarVisibleWidth) {
216-
// tab is scrolled too far to the right - make sure it's visible
255+
// tab is too far to the right
217256
const scrollAdjustment = tabRightRelative - tabBarVisibleWidth + 10; // 10px padding
218257
$tabBarElement.scrollLeft(currentScroll + scrollAdjustment);
219258
}

src/styles/Extn-TabBar.less

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,14 @@
249249
.tab-close-icon-overflow {
250250
font-size: 0.75rem;
251251
font-weight: 300;
252-
padding: 0.2rem 0.5rem;
252+
padding: 0.3rem 0.6rem;
253253
margin-left: 0.5rem;
254254
margin-top: -0.1rem;
255255
color: #CCC;
256256
transition: all 0.2s ease;
257257
border-radius: 0.25rem;
258-
pointer-events: none;
259258
}
260259

261-
.tab-close-icon-overflow:hover {
262-
background-color: rgba(255, 255, 255, 0.1);
260+
.tab-close-icon-overflow .fa-solid.fa-times:hover {
261+
color: #FFF;
263262
}

0 commit comments

Comments
 (0)