@@ -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 }
0 commit comments