JSFiddle - React, Tailwind, and code Playground

HTML

<div id = 'main'>
    <div id = 'n1' contenteditable=true> Content one</div>
    <div id = 'n2' contenteditable=true></div>
    <div id = 'n3' contenteditable=true> Content 3</div>
    <div id = 'n4' contenteditable=true> Content 4</div>
</div>

JavaScript

$('#main div').keydown(function(){
    if(!$(this).text().trim()){
      setCursorToEnd($(this).prev().get(0));
    }
});


function setCursorToEnd(ele)
  {
    var range = document.createRange();
    var sel = window.getSelection();
    range.setStart(ele, 1);
    range.collapse(true);
    sel.removeAllRanges();
    sel.addRange(range);
    ele.focus();
  }