https://stackoverflow.com/a/6249440
function onContextMenu(e) {
e.preventDefault();
elementOnClick = e.target;
if(elementOnClick.tagName.toLowerCase() === 'div') {
if(elementOnClick.classList.contains('folder')) {
elementOnClick.setAttribute('contenteditable', 'true');
var range = document.createRange();
var sel = window.getSelection();
const pos = elementOnClick.childNodes[0].textContent.length
range.setStart(elementOnClick.childNodes[0], pos);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
elementOnClick.focus();
console.log('Elem FOLDER');
} else if(elementOnClick.classList.contains('file')) {
elementOnClick.setAttribute('contenteditable', 'true');
var range = document.createRange();
var sel = window.getSelection();
const pos = elementOnClick.childNodes[0].textContent.lastIndexOf('.')
range.setStart(elementOnClick.childNodes[0], pos);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
elementOnClick.focus();
console.log('Elem FILE');
}
} else {
console.log('EMPTY');
}
document.addEventListener('click', onMouseClick, false);
}