From ab380bf36104b49e6d5aaa9f3aa8c1b437fa836a Mon Sep 17 00:00:00 2001 From: llj Date: Fri, 12 Aug 2016 19:10:49 +0800 Subject: [PATCH] [lib/dirent] improved 'rename' --- static/scripts/app/views/dialogs/dirent-rename.js | 10 +++++++++- static/scripts/app/views/dirent.js | 10 ++++++++-- static/scripts/app/views/repo.js | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/static/scripts/app/views/dialogs/dirent-rename.js b/static/scripts/app/views/dialogs/dirent-rename.js index 50871d81d4..364dd1829c 100644 --- a/static/scripts/app/views/dialogs/dirent-rename.js +++ b/static/scripts/app/views/dialogs/dirent-rename.js @@ -15,9 +15,17 @@ define([ this.dir = options.dir; this.render(); - this.$el.modal({appendTo:'#main'}); + this.$el.modal({appendTo:'#main', focus: false}); $('#simplemodal-container').css({'width':'auto', 'height':'auto'}); + var $input = this.$('[name="newname"]'); + var dot_index = this.dirent.get('obj_name').lastIndexOf('.'); + if (!this.dirent.get('is_dir') && dot_index != -1) { + $input[0].setSelectionRange(0, dot_index); + } else { + $input.select(); + } + this.$error = this.$('.error'); this.$form = this.$('form'); }, diff --git a/static/scripts/app/views/dirent.js b/static/scripts/app/views/dirent.js index 1c5bdd2654..2f1a57a8ee 100644 --- a/static/scripts/app/views/dirent.js +++ b/static/scripts/app/views/dirent.js @@ -253,7 +253,6 @@ define([ }, rename: function() { - var is_dir = this.model.get('is_dir'); var dirent_name = this.model.get('obj_name'); var form = $(this.renameTemplate({ @@ -269,7 +268,14 @@ define([ }).append(form); $op.hide(); $name.hide(); - $('[name="newname"]', form).focus(); + + var $input = $('[name="newname"]', form); + var dot_index = dirent_name.lastIndexOf('.'); + if (!this.model.get('is_dir') && dot_index != -1) { + $input[0].setSelectionRange(0, dot_index); + } else { + $input.select(); + } this._hideMenu(); app.ui.freezeItemHightlight = true; diff --git a/static/scripts/app/views/repo.js b/static/scripts/app/views/repo.js index 8cc7691f13..5b5047aac0 100644 --- a/static/scripts/app/views/repo.js +++ b/static/scripts/app/views/repo.js @@ -118,7 +118,7 @@ define([ }).append(form); $op_td.hide(); $name_span.hide(); - $('[name="newname"]', form).focus(); + $('[name="newname"]', form).select(); this.togglePopup(); app.ui.freezeItemHightlight = true;