]> Untitled Git - lemmy-ui.git/commitdiff
Smart select inner content after bold or italics. Fixes #497 (#577)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 14 Feb 2022 19:43:07 +0000 (14:43 -0500)
committerGitHub <noreply@github.com>
Mon, 14 Feb 2022 19:43:07 +0000 (19:43 +0000)
src/shared/components/common/markdown-textarea.tsx

index 5b1c8ee0b219cc7b9a112c0d06d0694240327062..381ecb460c7793739481f75bf041c060883c1178 100644 (file)
@@ -459,6 +459,21 @@ export class MarkdownTextArea extends Component<
     }
     this.contentChange();
     this.setState(this.state);
+
+    textarea.focus();
+
+    if (start !== end) {
+      textarea.setSelectionRange(
+        start + beforeChars.length,
+        end + afterChars.length
+      );
+    } else {
+      textarea.setSelectionRange(
+        start + beforeChars.length,
+        end + emptyChars.length + afterChars.length
+      );
+    }
+
     setTimeout(() => {
       autosize.update(textarea);
     }, 10);