summaryrefslogtreecommitdiffstats
path: root/ui/src/components/comment-form.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-07-09 09:47:26 -0400
committerDessalines <tyhou13@gmx.com>2020-07-09 09:47:26 -0400
commit75251f6e7868a12420be06d08168dbdf1ed4bc88 (patch)
tree15e6905c5eeea2846da1d67042800f58657a812c /ui/src/components/comment-form.tsx
parent3f34e5dadfce3924554315ab9d60ec244fff0de5 (diff)
Adding select quoting of text for comments. Fixes #790
Diffstat (limited to 'ui/src/components/comment-form.tsx')
-rw-r--r--ui/src/components/comment-form.tsx18
1 files changed, 17 insertions, 1 deletions
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<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() {