Fix enter key sometimes putting two newlines in editor

This happens when, in a Chromium-based browser, you try to insert a
newline at the end of the last action of your story.
This commit is contained in:
vfbd 2022-06-30 12:03:39 -04:00
parent ce5f4d3dda
commit cccf8296fc
1 changed files with 5 additions and 0 deletions

View File

@ -1420,9 +1420,14 @@ function chunkOnTextInput(event) {
// to put the <br/> back in the right place
var br = $("#_EDITOR_LINEBREAK_")[0];
if(br.parentNode === game_text[0]) {
var parent = br.previousSibling;
if(br.previousSibling.nodeType !== 1) {
parent = br.previousSibling.previousSibling;
br.previousSibling.previousSibling.appendChild(br.previousSibling);
}
if(parent.lastChild.tagName === "BR") {
parent.lastChild.remove(); // Chrome also inserts an extra <br/> in this case for some reason so we need to remove it
}
br.previousSibling.appendChild(br);
r.selectNodeContents(br.parentNode);
s.removeAllRanges();