From: Dessalines Date: Thu, 9 Jul 2020 13:47:26 +0000 (-0400) Subject: Adding select quoting of text for comments. Fixes #790 X-Git-Url: http://these/git/readmes/%7B%60%24%7BwebArchiveUrl%7D/save/static/%7BelementUrl%7D?a=commitdiff_plain;h=75251f6e7868a12420be06d08168dbdf1ed4bc88;p=lemmy.git Adding select quoting of text for comments. Fixes #790 --- diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx index 770c127c..32bc3786 100644 --- a/ui/src/components/comment-form.tsx +++ b/ui/src/components/comment-form.tsx @@ -98,7 +98,7 @@ export class CommentForm extends Component { } 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 { 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() {