diff --git a/client/src/views/fields/text.js b/client/src/views/fields/text.js index f496378a2f..85d6bc0eb4 100644 --- a/client/src/views/fields/text.js +++ b/client/src/views/fields/text.js @@ -630,7 +630,7 @@ class TextFieldView extends BaseFieldView { const after = value.substring(selectionEnd); // Last line, a list item syntax. - const match = before.match(/(^|\n)( *[-*]|\d+\.)[^\n]*$/); + const match = before.match(/(^|\n)( *[-*]|\d+\.)([^\n]*)$/); if (!match) { return; @@ -638,6 +638,15 @@ class TextFieldView extends BaseFieldView { event.preventDefault(); + if (match[3].trim() === '') { + target.value = before.substring(0, match.index) + '\n' + after; + target.selectionStart = target.selectionEnd = target.value.length - after.length; + + this.controlTextareaHeight(); + + return; + } + let itemPart = match[2]; const matchPart = itemPart.match(/( *)(\d+)/); @@ -653,6 +662,7 @@ class TextFieldView extends BaseFieldView { const newLine = "\n" + itemPart + " "; target.value = before + newLine + after; + target.selectionStart = target.selectionEnd = target.value.length - after.length; this.controlTextareaHeight(); }