Fix quotedText bugs in markdown editor
authorsunaurus <sander@saarend.com>
Sat, 1 Jul 2023 16:46:42 +0000 (19:46 +0300)
committersunaurus <sander@saarend.com>
Sat, 1 Jul 2023 16:57:06 +0000 (19:57 +0300)
src/shared/components/common/markdown-textarea.tsx

index 5623ace5dcf4bd78301d40dde90b1e2458286fa2..5912537256d8c46563664384e3c9fc3ff6253e8a 100644 (file)
@@ -702,18 +702,20 @@ export class MarkdownTextArea extends Component<
   quoteInsert() {
     const textarea: any = document.getElementById(this.id);
     const selectedText = window.getSelection()?.toString();
-    const { content } = this.state;
+    let { content } = this.state;
     if (selectedText) {
       const quotedText =
         selectedText
           .split("\n")
           .map(t => `> ${t}`)
           .join("\n") + "\n\n";
+
       if (!content) {
-        this.setState({ content: "" });
+        content = "";
       } else {
-        this.setState({ content: `${content}\n` });
+        content = `${content}\n\n`;
       }
+
       this.setState({
         content: `${content}${quotedText}`,
       });