Skip to content

Commit 9653453

Browse files
committed
feat: add 'x' button to remove specific file from Recent Files
1 parent 23dd1dc commit 9653453

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

src/extensionsIntegrated/NavigationAndHistory/main.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,33 +239,66 @@ define(function (require, exports, module) {
239239
// Try to see if we have same doc split
240240
// Check existing list for this doc path and active pane entry
241241
var entryIndex = _.findIndex(_mrofList, function (record) {
242-
return (record && record.file === value.file && record.paneId === MainViewManager.getActivePaneId());
242+
return (
243+
record &&
244+
record.file === value.file &&
245+
record.paneId === MainViewManager.getActivePaneId()
246+
);
243247
});
244248

245249
// If found don't process this entry, as the document is already present in active pane
246250
if (entryIndex >= 0) {
247251
return true;
248252
}
249-
// Process this for active pane id
253+
// Process this for active pane id
250254
value.paneId = MainViewManager.getActivePaneId();
251255

252256
}
253257

254258
var indxInWS = MainViewManager.findInWorkingSet(value.paneId, value.file);
255259

256-
data = {fullPath: value.file,
260+
data = {
261+
fullPath: value.file,
257262
name: FileUtils.getBaseName(value.file),
258-
isFile: true};
263+
isFile: true
264+
};
259265

260266
fileEntry = FileSystem.getFileForPath(value.file);
261267

262268
// Create new list item with a link
263-
$link = $("<a href='#' class='mroitem'></a>").html(ViewUtils.getFileEntryDisplay({name: FileUtils.getBaseName(value.file)}));
269+
$link = $("<a href='#' class='mroitem'></a>").html(
270+
ViewUtils.getFileEntryDisplay({name: FileUtils.getBaseName(value.file)})
271+
);
272+
273+
// Create remove button
274+
var $removeBtn = $("<span class='remove-file'>&times;</span>").on("click", function(e) {
275+
e.preventDefault();
276+
e.stopPropagation();
277+
278+
// Find and remove the entry from _mrofList
279+
var filePath = $(this).parent().data("path");
280+
var paneId = $(this).parent().data("paneId");
281+
282+
_mrofList = _mrofList.filter(function(entry) {
283+
return !(entry && entry.file === filePath && entry.paneId === paneId);
284+
});
285+
286+
// Remove the list item from UI
287+
$(this).parent().remove();
288+
289+
// Update preferences
290+
PreferencesManager.setViewState(
291+
OPEN_FILES_VIEW_STATE,
292+
_mrofList,
293+
PreferencesManager.STATE_PROJECT_CONTEXT
294+
);
295+
});
264296

265297
// Use the file icon providers
266298
WorkingSetView.useIconProviders(data, $link);
267299

268-
$newItem = $("<li></li>").append($link);
300+
// Create list item with link and remove button
301+
$newItem = $("<li></li>").append($link).append($removeBtn);
269302

270303
if (indxInWS !== -1) { // in working set show differently
271304
$newItem.addClass("working-set");
@@ -285,7 +318,7 @@ define(function (require, exports, module) {
285318
// Use the class providers(git e.t.c)
286319
WorkingSetView.useClassProviders(data, $newItem);
287320

288-
// If a file is dirty , mark it in the list
321+
// If a file is dirty, mark it in the list
289322
if (_isOpenAndDirty(fileEntry)) {
290323
$(dirtyDotTemplate).prependTo($newItem);
291324
}

src/styles/Extn-NavigationAndHistory.less

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,27 @@
236236
#mrof-container .footer {
237237
background-color: #2c2c2c;
238238
border-top: 1px solid #343434;
239+
}
240+
241+
#mrof-list li {
242+
position: relative;
243+
}
244+
245+
.remove-file {
246+
position: absolute;
247+
right: 8px;
248+
top: 50%;
249+
transform: translateY(-50%);
250+
cursor: pointer;
251+
opacity: 0.6;
252+
font-size: 18px;
253+
display: none;
254+
}
255+
256+
#mrof-list li:hover .remove-file {
257+
display: block;
258+
}
259+
260+
.remove-file:hover {
261+
opacity: 1;
239262
}

0 commit comments

Comments
 (0)