Skip to content

Commit

Permalink
[ui:cwd] correction of multi-line filename editing
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Nov 12, 2015
1 parent b3ddd45 commit 7bf75e3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
17 changes: 12 additions & 5 deletions js/commands/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ elFinder.prototype.commands.rename = function() {
type = (hashes && hashes._type)? hashes._type : (fm.selected().length? 'files' : 'navbar'),
incwd = (fm.cwd().hash == file.hash),
tarea = (type === 'files' && fm.storage('view') != 'list'),
rest = function(){
if (tarea) {
node.parent().zIndex('').css('position', '');
node.css('max-height', '');
}
},
dfrd = $.Deferred()
.done(function(data){
incwd && fm.exec('open', data.added[0].hash);
Expand All @@ -35,6 +41,10 @@ elFinder.prototype.commands.rename = function() {
var parent = input.parent(),
name = fm.escape(file.name);

if (tarea) {
name = name.replace(/([_.])/g, '​$1');
}
rest();
if (type === 'navbar') {
input.replaceWith(name);
} else {
Expand All @@ -52,16 +62,12 @@ elFinder.prototype.commands.rename = function() {
error && fm.error(error);
})
.always(function() {
if (tarea) {
node.parent().zIndex('').css('position', '');
node.css('max-height', '');
}
fm.enable();
}),
input = $(tarea? '<textarea/>' : '<input type="text"/>')
.keyup(function(){
if (tarea) {
this.style.height = 'auto';
this.style.height = '1px';
this.style.height = this.scrollHeight + 'px';
}
})
Expand Down Expand Up @@ -102,6 +108,7 @@ elFinder.prototype.commands.rename = function() {
return dfrd.reject(['errExists', name]);
}

rest();
parent.html(fm.escape(name));
fm.lockfiles({files : [file.hash]});
fm.request({
Expand Down
25 changes: 23 additions & 2 deletions js/elFinder.resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ elFinder.prototype.resources = {
var fm = this.fm,
cmd = this.name,
cwd = fm.getUI('cwd'),
tarea= (fm.storage('view') != 'list'),
rest = function(){
if (tarea) {
node.zIndex('').css('position', '');
nameelm.css('max-height', '');
}
},
dfrd = $.Deferred()
.fail(function(error) {
rest();
cwd.trigger('unselectall');
error && fm.error(error);
})
Expand All @@ -83,7 +91,14 @@ elFinder.prototype.resources = {
},
data = this.data || {},
node = cwd.trigger('create.'+fm.namespace, file).find('#'+id),
input = $('<input type="text"/>')
nameelm,
input = $(tarea? '<textarea/>' : '<input type="text"/>')
.keyup(function(){
if (tarea) {
this.style.height = '1px';
this.style.height = this.scrollHeight + 'px';
}
})
.keydown(function(e) {
e.stopImmediatePropagation();

Expand All @@ -109,6 +124,7 @@ elFinder.prototype.resources = {
return dfrd.reject(['errExists', name]);
}

rest();
parent.html(fm.escape(name));

fm.lockfiles({files : [id]});
Expand Down Expand Up @@ -140,7 +156,12 @@ elFinder.prototype.resources = {
}

fm.disable();
node.find('.elfinder-cwd-filename').empty('').append(input.val(file.name));
nameelm = node.find('.elfinder-cwd-filename').empty('').append(input.val(file.name));
if (tarea) {
node.zIndex((node.parent().zIndex()) + 1).css('position', 'relative');
nameelm.css('max-height', 'none');
input.trigger('keyup');
}
input.select().focus();
input[0].setSelectionRange && input[0].setSelectionRange(0, file.name.replace(/\..+$/, '').length);

Expand Down

0 comments on commit 7bf75e3

Please sign in to comment.