]> source.dussan.org Git - gitea.git/commitdiff
Focus editor on "Write" tab click (#26714)
authorsilverwind <me@silverwind.io>
Fri, 25 Aug 2023 05:26:32 +0000 (07:26 +0200)
committerGitHub <noreply@github.com>
Fri, 25 Aug 2023 05:26:32 +0000 (13:26 +0800)
Focus the editor when clicking the "Write" tab. Works for both Textarea
and EasyMDE. Does for some reason not work without the
`requestAnimationFrame`.

web_src/js/features/comp/ComboMarkdownEditor.js

index 9826f2f2bf24698f8d9fe18bb0381d42335fbc35..d486c5830acc8d8a268541a6d2668a9852874a57 100644 (file)
@@ -135,6 +135,12 @@ class ComboMarkdownEditor {
     $panelPreviewer.attr('data-tab', `markdown-previewer-${elementIdCounter}`);
     elementIdCounter++;
 
+    $tabEditor[0].addEventListener('click', () => {
+      requestAnimationFrame(() => {
+        this.focus();
+      });
+    });
+
     $tabs.tab();
 
     this.previewUrl = $tabPreviewer.attr('data-preview-url');