codejar
codejar copied to clipboard
Deleting last line
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).
Is it in Chrome or Firefox? I assume this is contenteditable behaviour.
This is from Chrome and Safari.
Firefox has a whole set of other problems and it is not usable for editing text.
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.
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