Explorar o código

BugFix: TextAreaEditor

Yuki Takei %!s(int64=7) %!d(string=hai) anos
pai
achega
9cc6d46b5d
Modificáronse 1 ficheiros con 6 adicións e 3 borrados
  1. 6 3
      resource/js/components/PageEditor/TextAreaEditor.js

+ 6 - 3
resource/js/components/PageEditor/TextAreaEditor.js

@@ -90,7 +90,6 @@ export default class TextAreaEditor extends AbstractEditor {
   insertText(text) {
     const startPos = this.textarea.selectionStart;
     const endPos = this.textarea.selectionEnd;
-
     this.replaceValue(text, startPos, endPos);
   }
 
@@ -125,13 +124,17 @@ export default class TextAreaEditor extends AbstractEditor {
 
   getEolPos() {
     const currentPos = this.textarea.selectionStart;
-    return this.textarea.value.indexOf('\n', currentPos);
+    const pos = this.textarea.value.indexOf('\n', currentPos);
+    if (pos < 0) {  // not found but EOF
+      return this.textarea.value.length;
+    }
+    return pos;
   }
 
   replaceValue(text, startPos, endPos) {
     // create new value
     const value = this.textarea.value;
-    const newValue = value.substring(0, startPos) + text + value.substring(endPos, value.length-1);
+    const newValue = value.substring(0, startPos) + text + value.substring(endPos, value.length);
     // calculate new position
     const newPos = startPos + text.length;