Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Recent Projects - Pressing delete key removes project from list #5354

Merged
merged 2 commits into from
Oct 21, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/extensions/default/RecentProjects/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,35 @@ define(function (require, exports, module) {
removeDeleteButton();
}

/**
* Deletes the selected item and
* move the focus to next item in list.
*
* @return {boolean} TRUE if project is removed
*/
function removeSelectedItem(e) {
var recentProjects = getRecentProjects(),
$cacheItem = $dropdownItem,
index = recentProjects.indexOf($cacheItem.data("path"));

// When focus is not on project item
if (index === -1) {
return false;
}

// remove project
recentProjects.splice(index, 1);
prefs.setValue("recentProjects", recentProjects);
checkHovers(e.pageX, e.pageY);

if (recentProjects.length === 1) {
$dropdown.find(".divider").remove();
}
selectNextItem(+1);
$cacheItem.closest("li").remove();
return true;
}

/**
* Handles the Key Down events
* @param {KeyboardEvent} event
Expand All @@ -202,6 +231,13 @@ define(function (require, exports, module) {
}
keyHandled = true;
break;
case KeyEvent.DOM_VK_BACK_SPACE:
case KeyEvent.DOM_VK_DELETE:
if ($dropdownItem) {
removeSelectedItem(event);
keyHandled = true;
}
break;
}

if (keyHandled) {
Expand Down