From 280885e8e8a84e259efc1f0bf6bb6768f3e4cecc Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 3 Feb 2022 14:08:16 -0600 Subject: [PATCH] forum posts: fix the "post reply" link scrolling to top of page. Fix regression in 6fbca01a2. Also make it so the "reply" link automatically inserts the cursor into the reply box. Do this for both forum posts and comments. Before it only did this when quoting a post, not when creating a new post. --- app/components/comment_component/comment_component.js | 1 + app/components/forum_post_component/forum_post_component.js | 3 ++- app/views/forum_posts/new.js.erb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/components/comment_component/comment_component.js b/app/components/comment_component/comment_component.js index 22a626354..58b5c6f60 100644 --- a/app/components/comment_component/comment_component.js +++ b/app/components/comment_component/comment_component.js @@ -16,6 +16,7 @@ class CommentComponent { var $form = $(e.target).closest("div.new-comment").find("form"); $form.show(); $form[0].scrollIntoView(false); + $form.find("textarea").selectEnd(); e.preventDefault(); } diff --git a/app/components/forum_post_component/forum_post_component.js b/app/components/forum_post_component/forum_post_component.js index 37b19931e..67d566a01 100644 --- a/app/components/forum_post_component/forum_post_component.js +++ b/app/components/forum_post_component/forum_post_component.js @@ -13,7 +13,8 @@ class ForumPostComponent { static showNewForumPostForm(e) { $("#topic-response").show(); - document.body.scrollIntoView(false); + $("#forum_post_body").get(0).scrollIntoView(false); + $("#forum_post_body").selectEnd(); e.preventDefault(); } diff --git a/app/views/forum_posts/new.js.erb b/app/views/forum_posts/new.js.erb index 92bcc3378..6f9805b99 100644 --- a/app/views/forum_posts/new.js.erb +++ b/app/views/forum_posts/new.js.erb @@ -4,5 +4,5 @@ if ($("#forum_post_body").val().length > 0) { } $("#forum_post_body").val(msg); $("#topic-response").show(); -document.body.scrollIntoView(false); +$("#forum_post_body").get(0).scrollIntoView(false); $("#forum_post_body").selectEnd();