Skip to content

Commit 835a37d

Browse files
committed
feat: add reopen closed file feature ctrl-shift-t reassigned low use
1 parent 5e010c2 commit 835a37d

7 files changed

Lines changed: 48 additions & 6 deletions

File tree

src/base-config/keyboard.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@
290290
"navigate.gotoDefinition": [
291291
"Ctrl-T"
292292
],
293-
"navigate.gotoDefinitionInProject": [
294-
"Ctrl-Shift-T"
295-
],
296293
"navigate.jumptoDefinition": [
297294
"Ctrl-J"
298295
],

src/command/Commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ define(function (require, exports, module) {
4949
exports.FILE_CLOSE = "file.close"; // DocumentCommandHandlers.js handleFileClose()
5050
exports.FILE_CLOSE_ALL = "file.close_all"; // DocumentCommandHandlers.js handleFileCloseAll()
5151
exports.FILE_CLOSE_LIST = "file.close_list"; // DocumentCommandHandlers.js handleFileCloseList()
52+
exports.FILE_REOPEN_CLOSED = "file.reopen_closed"; // DocumentCommandHandlers.js handleReopenClosed()
5253
exports.FILE_OPEN_DROPPED_FILES = "file.openDroppedFiles"; // DragAndDrop.js openDroppedFiles()
5354
exports.FILE_LIVE_FILE_PREVIEW = "file.liveFilePreview"; // LiveDevelopment/main.js _handleGoLiveCommand()
5455
exports.FILE_LIVE_FILE_PREVIEW_SETTINGS = "file.liveFilePreviewSettings"; // LiveDevelopment/main.js _handleGoLiveCommand()

src/command/DefaultMenus.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ define(function (require, exports, module) {
7575
const fileCloseAllShortcut = isDesktop ? "Ctrl-Shift-W" : ""; // Ctrl-Alt-Shift-W` universal shortcut is set in keyboard.json
7676
const openFileShortcut = isDesktop ? "Ctrl-O" : "";
7777
const openFolderShortcut = isBrowser ? "Ctrl-O" : "";
78+
const reopenClosedShortcut = isBrowser ? "" : "Ctrl-Shift-T";
7879

7980
AppInit.htmlReady(function () {
8081
/**
@@ -119,6 +120,7 @@ define(function (require, exports, module) {
119120
menu.addMenuItem(Commands.FILE_OPEN_FOLDER, openFolderShortcut);
120121
menu.addMenuItem(Commands.FILE_CLOSE, fileCloseShortcut);
121122
menu.addMenuItem(Commands.FILE_CLOSE_ALL, fileCloseAllShortcut);
123+
menu.addMenuItem(Commands.FILE_REOPEN_CLOSED, reopenClosedShortcut);
122124
menu.addMenuDivider();
123125
menu.addMenuItem(Commands.FILE_SAVE);
124126
menu.addMenuItem(Commands.FILE_SAVE_ALL);

src/document/DocumentCommandHandlers.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,38 @@ define(function (require, exports, module) {
13201320
return saveAll();
13211321
}
13221322

1323+
let closedFilesHistory = new Map();
1324+
1325+
function _enableOrDisableReopenClosedCmd() {
1326+
CommandManager.get(Commands.FILE_REOPEN_CLOSED).setEnabled(!!closedFilesHistory.size);
1327+
}
1328+
1329+
function _addToClosedFilesHistory(filePath, paneID) {
1330+
closedFilesHistory.set(filePath, {paneID, closeTime: Date.now()});
1331+
_enableOrDisableReopenClosedCmd();
1332+
}
1333+
1334+
function handleReopenClosed() {
1335+
// find the file that was most recently closed
1336+
let leastRecentlyClosedPath, leastRecentlyClosedTime, paneToUse;
1337+
for(let closedFilePath of closedFilesHistory.keys()){
1338+
const currentScan = closedFilesHistory.get(closedFilePath);
1339+
if(!leastRecentlyClosedPath || leastRecentlyClosedTime < currentScan.closeTime) {
1340+
leastRecentlyClosedPath = closedFilePath;
1341+
leastRecentlyClosedTime = currentScan.closeTime;
1342+
paneToUse = currentScan.paneID;
1343+
}
1344+
}
1345+
if(leastRecentlyClosedPath) {
1346+
closedFilesHistory.delete(leastRecentlyClosedPath);
1347+
if(MainViewManager.getPaneCount() === 1) {
1348+
paneToUse = MainViewManager.ACTIVE_PANE;
1349+
}
1350+
FileViewController.openFileAndAddToWorkingSet(leastRecentlyClosedPath, paneToUse);
1351+
}
1352+
_enableOrDisableReopenClosedCmd();
1353+
}
1354+
13231355
/**
13241356
* Closes the specified file: removes it from the workingset, and closes the main editor if one
13251357
* is open. Prompts user about saving changes first, if document is dirty.
@@ -1339,7 +1371,8 @@ define(function (require, exports, module) {
13391371
promptOnly,
13401372
_forceClose,
13411373
_spawnedRequest,
1342-
paneId = MainViewManager.ACTIVE_PANE;
1374+
paneId = MainViewManager.ACTIVE_PANE,
1375+
activePaneID = MainViewManager.getActivePaneId();
13431376

13441377
if (commandData) {
13451378
file = commandData.file;
@@ -1353,6 +1386,11 @@ define(function (require, exports, module) {
13531386
function doClose(file) {
13541387
if (!promptOnly) {
13551388
MainViewManager._close(paneId, file);
1389+
let paneClosing = paneId;
1390+
if(paneId === MainViewManager.ACTIVE_PANE){
1391+
paneClosing = activePaneID;
1392+
}
1393+
_addToClosedFilesHistory(file.fullPath, paneClosing);
13561394
_fileClosed(file);
13571395
}
13581396
}
@@ -2192,6 +2230,8 @@ define(function (require, exports, module) {
21922230

21932231
let firstProjectOpenHandled = false;
21942232
ProjectManager.on(ProjectManager.EVENT_AFTER_PROJECT_OPEN, ()=>{
2233+
closedFilesHistory = new Map();
2234+
_enableOrDisableReopenClosedCmd();
21952235
if(firstProjectOpenHandled){
21962236
return;
21972237
}
@@ -2252,6 +2292,7 @@ define(function (require, exports, module) {
22522292
CommandManager.register(Strings.CMD_FILE_CLOSE, Commands.FILE_CLOSE, handleFileClose);
22532293
CommandManager.register(Strings.CMD_FILE_CLOSE_ALL, Commands.FILE_CLOSE_ALL, handleFileCloseAll);
22542294
CommandManager.register(Strings.CMD_FILE_CLOSE_LIST, Commands.FILE_CLOSE_LIST, handleFileCloseList);
2295+
CommandManager.register(Strings.CMD_REOPEN_CLOSED, Commands.FILE_REOPEN_CLOSED, handleReopenClosed);
22552296

22562297
// Traversal
22572298
CommandManager.register(Strings.CMD_NEXT_DOC, Commands.NAVIGATE_NEXT_DOC, handleGoNextDoc);

src/extensionsIntegrated/DisplayShortcuts/templates/bottom-panel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<a href="#" class="close">&times;</a>
55
<button class="btn reset-to-default" title="{{KEYBOARD_SHORTCUT_PANEL_RESET_DEFAULT}}">{{{KEYBOARD_SHORTCUT_PANEL_RESET}}}</button>
66
<input class="filter" type="search" placeholder="{{{KEYBOARD_SHORTCUT_PANEL_FILTER}}}">
7-
<span class="presetPickerContainer forced-hidden" title="{{KEYBOARD_SHORTCUT_PRESET_TOOLTIP}}"></span>
7+
<span class="presetPickerContainer" title="{{KEYBOARD_SHORTCUT_PRESET_TOOLTIP}}"></span>
88
</div>
99
<div class="resizable-content"></div>
1010
</div>

src/extensionsIntegrated/NavigationAndHistory/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ define(function (require, exports, module) {
731731
KeyBindingManager.addBinding(PREV_IN_RECENT_FILES, KeyboardPrefs[PREV_IN_RECENT_FILES]);
732732

733733
var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
734-
menu.addMenuItem(SHOW_RECENT_FILES, "", Menus.AFTER, Commands.FILE_OPEN_FOLDER);
734+
menu.addMenuItem(SHOW_RECENT_FILES, "", Menus.AFTER, Commands.FILE_REOPEN_CLOSED);
735735
}
736736

737737
function _initDefaultNavigationCommands() {

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ define({
464464
"CMD_OPEN_FOLDER": "Open Folder\u2026",
465465
"CMD_FILE_CLOSE": "Close",
466466
"CMD_FILE_CLOSE_ALL": "Close All",
467+
"CMD_REOPEN_CLOSED": "Reopen Closed File",
467468
"CMD_FILE_CLOSE_LIST": "Close List",
468469
"CMD_FILE_CLOSE_OTHERS": "Close Others",
469470
"CMD_FILE_CLOSE_ABOVE": "Close Others Above",

0 commit comments

Comments
 (0)