select everything before file extensions in drive when renaming

This commit is contained in:
ansuz 2017-07-07 10:37:12 +02:00
parent 1c462d5c4a
commit f9a43d6570

View File

@ -528,6 +528,12 @@ define([
module.displayDirectory(currentPath); module.displayDirectory(currentPath);
}; };
var getFileNameExtension = function (name) {
var matched = /\.\S+$/.exec(name);
if (matched && matched.length) { return matched[matched.length -1]; }
return '';
};
// Replace a file/folder name by an input to change its value // Replace a file/folder name by an input to change its value
var displayRenameInput = function ($element, path) { var displayRenameInput = function ($element, path) {
// NOTE: setTimeout(f, 0) otherwise the "rename" button in the toolbar is not working // NOTE: setTimeout(f, 0) otherwise the "rename" button in the toolbar is not working
@ -551,6 +557,7 @@ define([
value: name value: name
}).data('path', path); }).data('path', path);
// Stop propagation on keydown to avoid issues with arrow keys // Stop propagation on keydown to avoid issues with arrow keys
$input.on('keydown', function (e) { e.stopPropagation(); }); $input.on('keydown', function (e) { e.stopPropagation(); });
@ -567,7 +574,12 @@ define([
//$element.parent().append($input); //$element.parent().append($input);
$name.after($input); $name.after($input);
$input.focus(); $input.focus();
$input.select();
var extension = getFileNameExtension(name);
var input = $input[0];
input.selectionStart = 0;
input.selectionEnd = name.length - extension.length;
// We don't want to open the file/folder when clicking on the input // We don't want to open the file/folder when clicking on the input
$input.on('click dblclick', function (e) { $input.on('click dblclick', function (e) {
removeSelected(); removeSelected();