mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 18:01:00 +00:00
Adding select quoting of text for comments. Fixes #790
This commit is contained in:
parent
3f34e5dadf
commit
75251f6e78
1 changed files with 17 additions and 1 deletions
18
ui/src/components/comment-form.tsx
vendored
18
ui/src/components/comment-form.tsx
vendored
|
@ -98,7 +98,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
var textarea: any = document.getElementById(this.id);
|
let textarea: any = document.getElementById(this.id);
|
||||||
autosize(textarea);
|
autosize(textarea);
|
||||||
this.tribute.attach(textarea);
|
this.tribute.attach(textarea);
|
||||||
textarea.addEventListener('tribute-replaced', () => {
|
textarea.addEventListener('tribute-replaced', () => {
|
||||||
|
@ -106,6 +106,22 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
autosize.update(textarea);
|
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() {
|
componentDidUpdate() {
|
||||||
|
|
Loading…
Reference in a new issue