]> Untitled Git - lemmy.git/commitdiff
Adding select quoting of text for comments. Fixes #790
authorDessalines <tyhou13@gmx.com>
Thu, 9 Jul 2020 13:47:26 +0000 (09:47 -0400)
committerDessalines <tyhou13@gmx.com>
Thu, 9 Jul 2020 13:47:26 +0000 (09:47 -0400)
ui/src/components/comment-form.tsx

index 770c127c7f45e54aa697479721bd60bdcd7477a6..32bc37860b6b428c1990c417fb974ad65644eef2 100644 (file)
@@ -98,7 +98,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
   }
 
   componentDidMount() {
-    var textarea: any = document.getElementById(this.id);
+    let textarea: any = document.getElementById(this.id);
     autosize(textarea);
     this.tribute.attach(textarea);
     textarea.addEventListener('tribute-replaced', () => {
@@ -106,6 +106,22 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
       this.setState(this.state);
       autosize.update(textarea);
     });
+
+    // Quoting of selected text
+    let selectedText = window.getSelection().toString();
+    if (selectedText) {
+      let quotedText =
+        selectedText
+          .split('\n')
+          .map(t => `> ${t}`)
+          .join('\n') + '\n\n';
+      this.state.commentForm.content = quotedText;
+      this.setState(this.state);
+      // Not sure why this needs a delay
+      setTimeout(() => autosize.update(textarea), 10);
+    }
+
+    textarea.focus();
   }
 
   componentDidUpdate() {