From 5d390c61aae57a8d463fa46d30408ec3e8366e55 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Sun, 18 Mar 2018 22:49:08 -0400 Subject: [PATCH] Focus new file name input when modal opens --- src/app/panels/file-panel.js | 2 +- src/app/ui/modal-dialog-custom.js | 9 +++++---- src/app/ui/modaldialog.js | 11 ++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index e3e8e4c919..371c435380 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -242,7 +242,7 @@ function filepanel (appAPI, filesProvider) { appAPI.switchFile(filesProvider['browser'].type + '/' + newName) } }) - }) + }, null, true) } /** diff --git a/src/app/ui/modal-dialog-custom.js b/src/app/ui/modal-dialog-custom.js index 470b4343e7..f793a892f6 100644 --- a/src/app/ui/modal-dialog-custom.js +++ b/src/app/ui/modal-dialog-custom.js @@ -6,8 +6,8 @@ module.exports = { alert: function (text) { modal('', yo`
${text}
`, null, { label: null }) }, - prompt: function (title, text, inputValue, ok, cancel) { - prompt(title, text, false, inputValue, ok, cancel) + prompt: function (title, text, inputValue, ok, cancel, focus) { + prompt(title, text, false, inputValue, ok, cancel, focus) }, promptPassphrase: function (title, text, inputValue, ok, cancel) { prompt(title, text, true, inputValue, ok, cancel) @@ -63,7 +63,7 @@ module.exports = { } } -function prompt (title, text, hidden, inputValue, ok, cancel) { +function prompt (title, text, hidden, inputValue, ok, cancel, focus) { if (!inputValue) inputValue = '' var type = hidden ? 'password' : 'text' var input = yo`` @@ -73,6 +73,7 @@ function prompt (title, text, hidden, inputValue, ok, cancel) { }, { fn: () => { if (typeof cancel === 'function') cancel() } - } + }, + focus ? '#prompt_text' : undefined ) } diff --git a/src/app/ui/modaldialog.js b/src/app/ui/modaldialog.js index 6cee053951..664dd9b0bc 100644 --- a/src/app/ui/modaldialog.js +++ b/src/app/ui/modaldialog.js @@ -1,7 +1,7 @@ var yo = require('yo-yo') var css = require('./styles/modaldialog-styles') -module.exports = (title, content, ok, cancel) => { +module.exports = (title, content, ok, cancel, focusSelector) => { var container = document.querySelector(`.${css.modal}`) if (!container) { document.querySelector('body').appendChild(html()) @@ -54,6 +54,15 @@ module.exports = (title, content, ok, cancel) => { function show () { container.style.display = 'block' + if (focusSelector) { + const focusTarget = document.querySelector(`.${css.modal} ${focusSelector}`) + if (focusTarget) { + focusTarget.focus() + if (typeof focusTarget.setSelectionRange === 'function') { + focusTarget.setSelectionRange(0, focusTarget.value.length) + } + } + } } function removeEventListener () {