Skip to content

Commit 1a81353

Browse files
devvaannshabose
authored andcommitted
feat: add placeholder tabs when file is selected from file tree
1 parent 65bee60 commit 1a81353

File tree

2 files changed

+106
-32
lines changed

2 files changed

+106
-32
lines changed

src/extensionsIntegrated/TabBar/main.js

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ define(function (require, exports, module) {
2323
const _ = require("thirdparty/lodash");
2424
const AppInit = require("utils/AppInit");
2525
const MainViewManager = require("view/MainViewManager");
26-
const EditorManager = require("editor/EditorManager");
2726
const FileSystem = require("filesystem/FileSystem");
2827
const PreferencesManager = require("preferences/PreferencesManager");
2928
const CommandManager = require("command/CommandManager");
@@ -135,16 +134,20 @@ define(function (require, exports, module) {
135134
const isPaneActive = (paneId === currentActivePane);
136135

137136
const isDirty = Helper._isFileModified(FileSystem.getFileForPath(entry.path));
137+
const isPlaceholder = entry.isPlaceholder === true;
138138

139-
// create tab with active class
139+
// create tab with all the appropriate classes
140140
const $tab = $(
141141
`<div class="tab
142-
${isActive ? 'active' : ''}
143-
${isDirty ? 'dirty' : ''}" data-path="${entry.path}" title="${entry.path}">
144-
<div class="tab-icon"></div>
145-
<div class="tab-name"></div>
146-
<div class="tab-close"><i class="fa-solid fa-times"></i></div>
147-
</div>`
142+
${isActive ? 'active' : ''}
143+
${isDirty ? 'dirty' : ''}
144+
${isPlaceholder ? 'placeholder' : ''}"
145+
data-path="${entry.path}"
146+
title="${entry.path}">
147+
<div class="tab-icon"></div>
148+
<div class="tab-name"></div>
149+
<div class="tab-close"><i class="fa-solid fa-times"></i></div>
150+
</div>`
148151
);
149152

150153
// Add the file icon
@@ -228,6 +231,35 @@ define(function (require, exports, module) {
228231
createTabBar();
229232
}
230233

234+
// Check for active files not in working set in any pane
235+
const activePane = MainViewManager.getActivePaneId();
236+
const firstPaneFile = MainViewManager.getCurrentlyViewedFile("first-pane");
237+
const secondPaneFile = MainViewManager.getCurrentlyViewedFile("second-pane");
238+
239+
// when a file is opened from the filetree and is not present in the working set, then it is a placeholder
240+
let firstPanePlaceholder = null;
241+
let secondPanePlaceholder = null;
242+
243+
// Check if active file in first pane is not in the working set
244+
if (firstPaneFile &&
245+
!Global.firstPaneWorkingSet.some(entry => entry.path === firstPaneFile.fullPath)) {
246+
firstPanePlaceholder = {
247+
path: firstPaneFile.fullPath,
248+
name: firstPaneFile.name,
249+
isPlaceholder: true
250+
};
251+
}
252+
253+
// Check if active file in second pane is not in the working set
254+
if (secondPaneFile &&
255+
!Global.secondPaneWorkingSet.some(entry => entry.path === secondPaneFile.fullPath)) {
256+
secondPanePlaceholder = {
257+
path: secondPaneFile.fullPath,
258+
name: secondPaneFile.name,
259+
isPlaceholder: true
260+
};
261+
}
262+
231263
if (Global.secondPaneWorkingSet.length === 1 &&
232264
(!$('#phoenix-tab-bar-2').length || $('#phoenix-tab-bar-2').is(':hidden'))) {
233265
createTabBar();
@@ -237,7 +269,7 @@ define(function (require, exports, module) {
237269
// Update first pane's tabs
238270
if ($firstTabBar.length) {
239271
$firstTabBar.empty();
240-
if (Global.firstPaneWorkingSet.length > 0) {
272+
if (Global.firstPaneWorkingSet.length > 0 || firstPanePlaceholder) {
241273

242274
// get the count of tabs that we want to display in the tab bar (from preference settings)
243275
// from preference settings or working set whichever smaller
@@ -251,57 +283,52 @@ define(function (require, exports, module) {
251283

252284
let displayedEntries = Global.firstPaneWorkingSet.slice(0, tabsCountP1);
253285

254-
const activeEditor = EditorManager.getActiveEditor();
255-
const activePath = activeEditor ? activeEditor.document.file.fullPath : null;
256-
if (activePath && !displayedEntries.some(entry => entry.path === activePath)) {
257-
let activeEntry = Global.firstPaneWorkingSet.find(entry => entry.path === activePath);
258-
if (activeEntry) {
259-
displayedEntries[displayedEntries.length - 1] = activeEntry;
260-
}
261-
}
286+
// Add working set tabs
262287
displayedEntries.forEach(function (entry) {
263288
$firstTabBar.append(createTab(entry, "first-pane"));
264289
});
290+
291+
// Add placeholder tab if needed
292+
if (firstPanePlaceholder) {
293+
$firstTabBar.append(createTab(firstPanePlaceholder, "first-pane"));
294+
}
265295
}
266296
}
267297

268298
const $secondTabBar = $('#phoenix-tab-bar-2');
269299
// Update second pane's tabs
270300
if ($secondTabBar.length) {
271301
$secondTabBar.empty();
272-
if (Global.secondPaneWorkingSet.length > 0) {
302+
if (Global.secondPaneWorkingSet.length > 0 || secondPanePlaceholder) {
273303

274304
let tabsCountP2 = Math.min(Global.secondPaneWorkingSet.length, Preference.tabBarNumberOfTabs);
275305
if (Preference.tabBarNumberOfTabs < 0) {
276306
tabsCountP2 = Global.secondPaneWorkingSet.length;
277307
}
278308

279309
let displayedEntries2 = Global.secondPaneWorkingSet.slice(0, tabsCountP2);
280-
const activeEditor = EditorManager.getActiveEditor();
281-
const activePath = activeEditor ? activeEditor.document.file.fullPath : null;
282-
if (activePath && !displayedEntries2.some(entry => entry.path === activePath)) {
283-
let activeEntry = Global.secondPaneWorkingSet.find(entry => entry.path === activePath);
284-
if (activeEntry) {
285-
displayedEntries2[displayedEntries2.length - 1] = activeEntry;
286-
}
287-
}
310+
311+
// Add working set tabs
288312
displayedEntries2.forEach(function (entry) {
289313
$secondTabBar.append(createTab(entry, "second-pane"));
290314
});
315+
316+
// Add placeholder tab if needed
317+
if (secondPanePlaceholder) {
318+
$secondTabBar.append(createTab(secondPanePlaceholder, "second-pane"));
319+
}
291320
}
292321
}
293322

294-
// if no files are present in a pane, we want to hide the tab bar for that pane
295-
if (Global.firstPaneWorkingSet.length === 0 && ($('#phoenix-tab-bar'))) {
323+
// if no files are present in a pane and no placeholder, we want to hide the tab bar for that pane
324+
if (Global.firstPaneWorkingSet.length === 0 && !firstPanePlaceholder && ($('#phoenix-tab-bar'))) {
296325
Helper._hideTabBar($('#phoenix-tab-bar'), $('#overflow-button'));
297326
}
298327

299-
if (Global.secondPaneWorkingSet.length === 0 && ($('#phoenix-tab-bar-2'))) {
328+
if (Global.secondPaneWorkingSet.length === 0 && !secondPanePlaceholder && ($('#phoenix-tab-bar-2'))) {
300329
Helper._hideTabBar($('#phoenix-tab-bar-2'), $('#overflow-button-2'));
301330
}
302331

303-
const activePane = MainViewManager.getActivePaneId();
304-
305332
// Now that tabs are updated, scroll to the active tab if necessary.
306333
if ($firstTabBar.length) {
307334
Overflow.toggleOverflowVisibility("first-pane");
@@ -396,7 +423,15 @@ define(function (require, exports, module) {
396423
const currentActivePane = MainViewManager.getActivePaneId();
397424
const isPaneActive = (paneId === currentActivePane);
398425
const currentFile = MainViewManager.getCurrentlyViewedFile(currentActivePane);
399-
if(isPaneActive && currentFile && currentFile.fullPath === filePath) {
426+
427+
// Check if this is a placeholder tab
428+
if ($(this).hasClass('placeholder')) {
429+
// Add the file to the working set when placeholder tab is clicked
430+
const fileObj = FileSystem.getFileForPath(filePath);
431+
MainViewManager.addToWorkingSet(paneId, fileObj);
432+
}
433+
434+
if (isPaneActive && currentFile && currentFile.fullPath === filePath) {
400435
return;
401436
}
402437
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filePath, paneId: paneId });

src/styles/Extn-TabBar.less

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,45 @@
240240
background-color: rgba(255, 255, 255, 0.1);
241241
}
242242

243+
.tab.placeholder .tab-name {
244+
font-style: italic;
245+
color: #888;
246+
}
247+
248+
.dark .tab.placeholder .tab-name {
249+
color: #888;
250+
}
251+
252+
.tab.placeholder.active .tab-name {
253+
color: #666;
254+
}
255+
256+
.dark .tab.placeholder.active .tab-name {
257+
color: #aaa;
258+
}
259+
260+
.tab.placeholder::after {
261+
content: "";
262+
position: absolute;
263+
top: 0;
264+
left: 0;
265+
right: 0;
266+
height: 0.12rem;
267+
background-color: #b4b2b2;
268+
}
269+
270+
.dark .tab.placeholder::after {
271+
background-color: #666;
272+
}
273+
274+
.tab.placeholder.active::after {
275+
background-color: #0078D7;
276+
}
277+
278+
.dark .tab.placeholder.active::after {
279+
background-color: #75BEFF;
280+
}
281+
243282
.tab.dragging {
244283
opacity: 0.7;
245284
transform: scale(0.95);

0 commit comments

Comments
 (0)