Fix cursor in the drive search bar

pull/1/head
yflory 8 years ago
parent 12cc49b575
commit 67f4096396

@ -126,6 +126,15 @@ define([
localStorage[LOCALSTORAGE_VIEWMODE] = mode; localStorage[LOCALSTORAGE_VIEWMODE] = mode;
}; };
var setSearchCursor = function () {
$input = $iframe.find('#searchInput');
localStorage.searchCursor = $input[0].selectionStart;
};
var getSearchCursor = function () {
return localStorage.searchCursor || 0;
}
var now = function () { var now = function () {
return new Date().getTime(); return new Date().getTime();
}; };
@ -1529,6 +1538,8 @@ define([
if (isSearch) { if (isSearch) {
$tree.find('#searchInput').focus(); $tree.find('#searchInput').focus();
$tree.find('#searchInput')[0].selectionStart = getSearchCursor();
$tree.find('#searchInput')[0].selectionEnd = getSearchCursor();
} }
if (!isWorkgroup()) { if (!isWorkgroup()) {
@ -1773,17 +1784,22 @@ define([
if (search.to) { window.clearTimeout(search.to); } if (search.to) { window.clearTimeout(search.to); }
var isInSearchTmp = currentPath[0] === SEARCH; var isInSearchTmp = currentPath[0] === SEARCH;
if ($input.val().trim() === "") { if ($input.val().trim() === "") {
setSearchCursor(0);
if (search.oldLocation.length) { displayDirectory(search.oldLocation); } if (search.oldLocation.length) { displayDirectory(search.oldLocation); }
return; return;
} }
if (e.which === 13) { if (e.which === 13) {
if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); } if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); }
displayDirectory([SEARCH, $input.val()]); var newLocation = [SEARCH, $input.val()];
setSearchCursor();
if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); }
return; return;
} }
search.to = window.setTimeout(function () { search.to = window.setTimeout(function () {
if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); } if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); }
displayDirectory([SEARCH, $input.val()]); var newLocation = [SEARCH, $input.val()];
setSearchCursor();
if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); }
}, 500); }, 500);
}).appendTo($div); }).appendTo($div);
if (isInSearch) { $input.val(currentPath[1] || ''); } if (isInSearch) { $input.val(currentPath[1] || ''); }

Loading…
Cancel
Save