Add new keyboard shortcuts for the drive search

pull/1/head
yflory 7 years ago
parent ce3600b026
commit e2cf46d725

@ -419,10 +419,6 @@ define([
var ev = {}; var ev = {};
if (e.ctrlKey) { ev.ctrlKey = true; } if (e.ctrlKey) { ev.ctrlKey = true; }
if (e.shiftKey) { ev.shiftKey = true; } if (e.shiftKey) { ev.shiftKey = true; }
var click = function (el) {
if (!el) { return; }
APP.onElementClick(ev, $(el));
};
// Enter // Enter
if (e.which === 13) { if (e.which === 13) {
@ -444,6 +440,11 @@ define([
if ([37, 38, 39, 40].indexOf(e.which) === -1) { return; } if ([37, 38, 39, 40].indexOf(e.which) === -1) { return; }
e.preventDefault(); e.preventDefault();
var click = function (el) {
if (!el) { return; }
APP.onElementClick(ev, $(el));
};
var $selection = $content.find('.cp-app-drive-element.cp-app-drive-element-selected'); var $selection = $content.find('.cp-app-drive-element.cp-app-drive-element-selected');
if ($selection.length === 0) { return void click($elements.first()[0]); } if ($selection.length === 0) { return void click($elements.first()[0]); }
@ -2386,6 +2387,13 @@ define([
if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); } if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); }
return; return;
} }
if (e.which === 27) {
$input.val('');
setSearchCursor(0);
if (search.oldLocation && search.oldLocation.length) { displayDirectory(search.oldLocation); }
else { displayDirectory([ROOT]); }
return;
}
if (APP.mobile()) { return; } if (APP.mobile()) { return; }
search.to = window.setTimeout(function () { search.to = window.setTimeout(function () {
if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); } if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); }
@ -2815,6 +2823,19 @@ define([
moveElements(paths, [TRASH], false, refresh); moveElements(paths, [TRASH], false, refresh);
} }
}); });
var isCharacterKey = function (e) {
return e.which === "undefined" /* IE */ ||
(e.which > 0 && e.which !== 13 && e.which !== 27 && !e.ctrlKey && !e.altKey);
};
$appContainer.on('keypress', function (e) {
var $searchBar = $tree.find('#cp-app-drive-tree-search-input');
if ($searchBar.is(':focus')) { return; }
if (isCharacterKey(e)) {
$searchBar.focus();
e.preventDefault();
return;
}
});
$appContainer.contextmenu(function () { $appContainer.contextmenu(function () {
APP.hideMenu(); APP.hideMenu();
return false; return false;

Loading…
Cancel
Save