codejar icon indicating copy to clipboard operation
codejar copied to clipboard

Deleting last line

Open junghoocho opened this issue 4 years ago • 4 comments

When I delete all characters in the last line, the cursor moves up to the previous line, which is different from the typical behavior of most editors. In all editors that I am used to, the cursor still stays in the last line without moving up. I wonder whether this behavior is intentional and whether there is any way to change it (or add an option to let it behave differently).

Jun-16-2020 09-32-42

junghoocho avatar Jun 16 '20 16:06 junghoocho

Is it in Chrome or Firefox? I assume this is contenteditable behaviour.

antonmedv avatar Jun 16 '20 18:06 antonmedv

This is from Chrome and Safari.

Firefox has a whole set of other problems and it is not usable for editing text.

junghoocho avatar Jun 16 '20 19:06 junghoocho

Looks like chrome deletes newline and there is no new node for placeholding. This is behaviour of contenteditable. I think it’s possible to override with custom behaviour.

antonmedv avatar Jun 16 '20 20:06 antonmedv

I was not able to find an appropriate solution for CodeJar yet. But here is a workaround if you'd like to add it in your custom highlight function.

Idea is to add extra \n at the end of the last line if there is none.

  // Add new line at end every time
  let html = editor.textContent
  if (html.length > 2 && html.substring(html.length - 2, html.length) != '\n\n') {
    html += '\n'
  }
  editor.innerHTML = html

antonmedv avatar Feb 05 '21 08:02 antonmedv