Skip to content

Commit 88aa624

Browse files
devvaannshabose
authored andcommitted
fix: close all tabs and close unmodified tabs now only close for the specified pane
1 parent 89b6afb commit 88aa624

File tree

1 file changed

+71
-57
lines changed

1 file changed

+71
-57
lines changed

src/extensionsIntegrated/TabBar/more-options.js

Lines changed: 71 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -81,49 +81,63 @@ define(function (require, exports, module) {
8181

8282
/**
8383
* "CLOSE ALL TABS"
84-
* This will close all tabs no matter whether they are in first pane or second pane
84+
* This will close all tabs in the specified pane
85+
*
86+
* @param {String} paneId - the id of the pane ["first-pane", "second-pane"]
8587
*/
86-
function handleCloseAllTabs() {
87-
CommandManager.execute(Commands.FILE_CLOSE_ALL);
88+
function handleCloseAllTabs(paneId) {
89+
if (!paneId) {
90+
return;
91+
}
92+
93+
let workingSet;
94+
workingSet = paneId === "first-pane" ? Global.firstPaneWorkingSet : Global.secondPaneWorkingSet;
95+
if (!workingSet || workingSet.length === 0) {
96+
return;
97+
}
98+
99+
// close each file in the pane, start from the rightmost [to avoid index shifts]
100+
for (let i = workingSet.length - 1; i >= 0; i--) {
101+
const fileObj = FileSystem.getFileForPath(workingSet[i].path);
102+
CommandManager.execute(
103+
Commands.FILE_CLOSE,
104+
{ file: fileObj, paneId: paneId }
105+
);
106+
}
88107
}
89108

90109

91110
/**
92111
* "CLOSE UNMODIFIED TABS"
93-
* This will close all tabs that are not modified
112+
* This will close all tabs that are not modified in the specified pane
113+
*
114+
* @param {String} paneId - the id of the pane ["first-pane", "second-pane"]
94115
*/
95-
function handleCloseUnmodifiedTabs() {
96-
const paneList = MainViewManager.getPaneIdList();
97-
98-
// for the first pane
99-
if (paneList.length > 0 && Global.firstPaneWorkingSet.length > 0) {
100-
// get all those entries that are not dirty
101-
const unmodifiedEntries = Global.firstPaneWorkingSet.filter(entry => !entry.isDirty);
116+
function handleCloseUnmodifiedTabs(paneId) {
117+
if (!paneId) {
118+
return;
119+
}
102120

103-
// close each unmodified file in the first pane
104-
unmodifiedEntries.forEach(entry => {
105-
const fileObj = FileSystem.getFileForPath(entry.path);
106-
CommandManager.execute(
107-
Commands.FILE_CLOSE,
108-
{ file: fileObj, paneId: "first-pane" }
109-
);
110-
});
121+
let workingSet;
122+
workingSet = paneId === "first-pane" ? Global.firstPaneWorkingSet : Global.secondPaneWorkingSet;
123+
if (!workingSet || workingSet.length === 0) {
124+
return;
111125
}
112126

113-
// for second pane
114-
if (paneList.length > 1 && Global.secondPaneWorkingSet.length > 0) {
115-
const unmodifiedEntries = Global.secondPaneWorkingSet.filter(entry => !entry.isDirty);
127+
// get all those entries that are not dirty
128+
const unmodifiedEntries = workingSet.filter(entry => !entry.isDirty);
116129

117-
unmodifiedEntries.forEach(entry => {
118-
const fileObj = FileSystem.getFileForPath(entry.path);
119-
CommandManager.execute(
120-
Commands.FILE_CLOSE,
121-
{ file: fileObj, paneId: "second-pane" }
122-
);
123-
});
130+
// close each unmodified file in the pane
131+
for (let i = unmodifiedEntries.length - 1; i >= 0; i--) {
132+
const fileObj = FileSystem.getFileForPath(unmodifiedEntries[i].path);
133+
CommandManager.execute(
134+
Commands.FILE_CLOSE,
135+
{ file: fileObj, paneId: paneId }
136+
);
124137
}
125138
}
126139

140+
127141
/**
128142
* "CLOSE TABS TO THE LEFT"
129143
* This function is responsible for closing all tabs to the left of the right-clicked tab
@@ -252,34 +266,34 @@ define(function (require, exports, module) {
252266
*/
253267
function _handleSelection(index, filePath, paneId) {
254268
switch (index) {
255-
case 0:
256-
// Close tab (the one that was right-clicked)
257-
handleCloseTab(filePath, paneId);
258-
break;
259-
case 1:
260-
// Close active tab
261-
handleCloseActiveTab();
262-
break;
263-
case 2:
264-
// Close tabs to the left
265-
handleCloseTabsToTheLeft(filePath, paneId);
266-
break;
267-
case 3:
268-
// Close tabs to the right
269-
handleCloseTabsToTheRight(filePath, paneId);
270-
break;
271-
case 4:
272-
// Close all tabs
273-
handleCloseAllTabs();
274-
break;
275-
case 5:
276-
// Close unmodified tabs
277-
handleCloseUnmodifiedTabs();
278-
break;
279-
case 6:
280-
// Reopen closed file
281-
reopenClosedFile();
282-
break;
269+
case 0:
270+
// Close tab (the one that was right-clicked)
271+
handleCloseTab(filePath, paneId);
272+
break;
273+
case 1:
274+
// Close active tab
275+
handleCloseActiveTab();
276+
break;
277+
case 2:
278+
// Close tabs to the left
279+
handleCloseTabsToTheLeft(filePath, paneId);
280+
break;
281+
case 3:
282+
// Close tabs to the right
283+
handleCloseTabsToTheRight(filePath, paneId);
284+
break;
285+
case 4:
286+
// Close all tabs
287+
handleCloseAllTabs(paneId);
288+
break;
289+
case 5:
290+
// Close unmodified tabs
291+
handleCloseUnmodifiedTabs(paneId);
292+
break;
293+
case 6:
294+
// Reopen closed file
295+
reopenClosedFile();
296+
break;
283297
}
284298
}
285299

0 commit comments

Comments
 (0)