@@ -188,21 +188,22 @@ define(function (require, exports, module) {
188188 // clean up any existing tab bars first and start fresh
189189 cleanupTabBar ( ) ;
190190
191- if ( $ ( '.not-editor' ) . length === 1 ) {
191+ const $paneHeader = $ ( '.pane-header' ) ;
192+ if ( $paneHeader . length === 1 ) {
192193 $tabBar = $ ( TabBarHTML ) ;
193194 // since we need to add the tab bar before the editor which has .not-editor class
194- $ ( ".not-editor " ) . before ( $tabBar ) ;
195+ $ ( ".pane-header " ) . after ( $tabBar ) ;
195196 WorkspaceManager . recomputeLayout ( true ) ;
196197 updateTabs ( ) ;
197198
198- } else if ( $ ( '.not-editor' ) . length === 2 ) {
199+ } else if ( $paneHeader . length === 2 ) {
199200 $tabBar = $ ( TabBarHTML ) ;
200201 $tabBar2 = $ ( TabBarHTML2 ) ;
201202
202203 // eq(0) is for the first pane and eq(1) is for the second pane
203204 // TODO: Fix bug where the tab bar gets hidden inside the editor in horizontal split
204- $ ( ".not-editor" ) . eq ( 0 ) . before ( $tabBar ) ;
205- $ ( ".not-editor" ) . eq ( 1 ) . before ( $tabBar2 ) ;
205+ $paneHeader . eq ( 0 ) . after ( $tabBar ) ;
206+ $paneHeader . eq ( 1 ) . after ( $tabBar2 ) ;
206207 WorkspaceManager . recomputeLayout ( true ) ;
207208 updateTabs ( ) ;
208209 }
@@ -344,6 +345,7 @@ define(function (require, exports, module) {
344345 }
345346 // Also check for any orphaned tab bars that might exist
346347 $ ( ".tab-bar-container" ) . remove ( ) ;
348+ WorkspaceManager . recomputeLayout ( true ) ;
347349 }
348350
349351
@@ -353,7 +355,7 @@ define(function (require, exports, module) {
353355 function handleTabClick ( ) {
354356
355357 // delegate event handling for both tab bars
356- $ ( document ) . on ( "click" , ".tab" , function ( event ) {
358+ $ ( document ) . on ( "click" , ".phoenix-tab-bar . tab" , function ( event ) {
357359 // check if the clicked element is the close button
358360 if ( $ ( event . target ) . hasClass ( 'fa-times' ) || $ ( event . target ) . closest ( '.tab-close' ) . length ) {
359361 // Get the file path from the data-path attribute of the parent tab
@@ -376,23 +378,35 @@ define(function (require, exports, module) {
376378 event . preventDefault ( ) ;
377379 event . stopPropagation ( ) ;
378380 }
379- return ;
380381 }
382+ } ) ;
381383
384+ // delegate event handling for both tab bars
385+ $ ( document ) . on ( "mousedown" , ".phoenix-tab-bar .tab" , function ( event ) {
386+ if ( $ ( event . target ) . hasClass ( 'fa-times' ) || $ ( event . target ) . closest ( '.tab-close' ) . length ) {
387+ return ;
388+ }
382389 // Get the file path from the data-path attribute
383390 const filePath = $ ( this ) . attr ( "data-path" ) ;
384391
385392 if ( filePath ) {
386- CommandManager . execute ( Commands . FILE_OPEN , { fullPath : filePath } ) ;
393+ // determine the pane inside which the tab belongs
394+ const isSecondPane = $ ( this ) . closest ( "#phoenix-tab-bar-2" ) . length > 0 ;
395+ const paneId = isSecondPane ? "second-pane" : "first-pane" ;
396+ const activeEditor = EditorManager . getActiveEditor ( ) ;
397+ const currentActivePane = MainViewManager . getActivePaneId ( ) ;
398+ const isPaneActive = ( paneId === currentActivePane ) ;
399+ if ( isPaneActive && activeEditor && activeEditor . document . file . fullPath === filePath ) {
400+ return ;
401+ }
402+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : filePath , paneId : paneId } ) ;
387403
388- // Prevent default behavior
389- event . preventDefault ( ) ;
390- event . stopPropagation ( ) ;
404+ // We dont prevent default behavior here to enable drag and drop of this tab
391405 }
392406 } ) ;
393407
394408 // Add the contextmenu (right-click) handler
395- $ ( document ) . on ( "contextmenu" , ".tab" , function ( event ) {
409+ $ ( document ) . on ( "contextmenu" , ".phoenix-tab-bar . tab" , function ( event ) {
396410 event . preventDefault ( ) ;
397411 event . stopPropagation ( ) ;
398412
0 commit comments