improve file name editing

pull/1/head
yann300 7 years ago
parent 4f7ffa3bd0
commit 4a63ffdd6c
  1. 14
      src/app/files/file-explorer.js

@ -220,13 +220,21 @@ function fileExplorer (appAPI, files) {
}) })
var textUnderEdit = null var textUnderEdit = null
var textInRename = false
function selectElementContents (el) {
var range = document.createRange()
range.selectNodeContents(el)
var sel = window.getSelection()
sel.removeAllRanges()
sel.addRange(range)
}
function editModeOn (label) { function editModeOn (label) {
textUnderEdit = label.innerText textUnderEdit = label.innerText
label.setAttribute('contenteditable', true) label.setAttribute('contenteditable', true)
label.classList.add(css.rename) label.classList.add(css.rename)
label.focus() label.focus()
selectElementContents(label)
} }
function editModeOff (event) { function editModeOff (event) {
@ -251,8 +259,7 @@ function fileExplorer (appAPI, files) {
} }
if (event.which === 13) event.preventDefault() if (event.which === 13) event.preventDefault()
if (!textInRename && (event.type === 'blur' || event.which === 27 || event.which === 13) && label.getAttribute('contenteditable')) { if (event.type === 'blur' || event.which === 13 && label.getAttribute('contenteditable')) {
textInRename = true
var isFolder = label.className.indexOf('folder') !== -1 var isFolder = label.className.indexOf('folder') !== -1
var save = textUnderEdit !== label.innerText var save = textUnderEdit !== label.innerText
if (save) { if (save) {
@ -260,7 +267,6 @@ function fileExplorer (appAPI, files) {
} }
label.removeAttribute('contenteditable') label.removeAttribute('contenteditable')
label.classList.remove(css.rename) label.classList.remove(css.rename)
textInRename = false
} }
} }
} }

Loading…
Cancel
Save