Просмотр исходного кода

impl TextAreaEditor.insertText

Yuki Takei 7 лет назад
Родитель
Сommit
9b1b48d770
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      resource/js/components/PageEditor/TextAreaEditor.js

+ 11 - 0
resource/js/components/PageEditor/TextAreaEditor.js

@@ -87,6 +87,17 @@ export default class TextAreaEditor extends AbstractEditor {
    * @inheritDoc
    * @inheritDoc
    */
    */
   insertText(text) {
   insertText(text) {
+    const startPos = this.textarea.selectionStart;
+    const endPos = this.textarea.selectionEnd;
+
+    // create new value
+    const value = this.textarea.value;
+    const newValue = value.substring(0, startPos) + text + value.substring(endPos, value.length-1);
+    // calculate new position
+    const newPos = startPos + text.length;
+
+    this.textarea.value = newValue;
+    this.textarea.setSelectionRange(newPos, newPos);
   }
   }
 
 
   /**
   /**