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 1 commit
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:
keyHandled = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be inside the if ($dropdownItem) { ... } ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that keyHandled is indication that popup have something to do with this key. When user presses DELETE key while the project menu is open, user expects some action on the recent project menu itself and no where else. We should consider that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but you want the key event to continue propagating if there is no $dropdownItem otherwise things stop working.

if ($dropdownItem) {
removeSelectedItem(event);
}
break;
}

if (keyHandled) {
Expand Down