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

Commit

Permalink
Merge pull request #5354 from sandeepjain/issue-5335
Browse files Browse the repository at this point in the history
Recent Projects - Pressing delete key removes project from list
  • Loading branch information
JeffryBooher committed Oct 21, 2013
2 parents af8a468 + 5ea1a68 commit ce74cb5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/extensions/default/RecentProjects/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,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 @@ -200,6 +229,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

0 comments on commit ce74cb5

Please sign in to comment.