ekad,
для стрелочек и прочего,
возможно есть вариант проще ...
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<style type="text/css">
[contenteditable] > div.active {
border: 4px red solid;
}
</style>
</head>
<body>
<div id="pt_text" contenteditable="true">
<div>111</div>
<div>111</div>
<div>(тут курсор)</div>
</div>
<script>
let edit = document.querySelector('#pt_text'),
div_active;
const deactivate = () => {
edit.querySelectorAll('.active').forEach(div => div_active === div || div.classList.remove('active'));
};
document.addEventListener('selectionchange', () => {
if (document.activeElement === edit) {
let el = window.getSelection().focusNode;
if (el.nodeType === 3) el = el.parentNode;
div_active = el;
deactivate();
div_active.classList.add('active');
}
});
edit.addEventListener('focusout', ()=>{div_active=null,deactivate()})
edit.addEventListener('keyup', deactivate)
</script>
</body>
</html>