Skip to content

A platform for community discussion. Free, open, simple.

FIX: Respect the End key when last post is already rendered (#28524)

Penar Musarajfe3d82a44a8d
diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js
index 7f16c7b5577..a0c56b9293e 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic.js
@@ -38,7 +38,6 @@ import discourseLater from "discourse-common/lib/later";
import { deepMerge } from "discourse-common/lib/object";
import discourseComputed, { bind } from "discourse-common/utils/decorators";
import I18n from "discourse-i18n";
-
let customPostMessageCallbacks = {};
const RETRIES_ON_RATE_LIMIT = 4;
@@ -931,12 +930,17 @@ export default class TopicController extends Controller.extend(
@action
jumpBottom() {
- // When a topic only has one lengthy post
- const jumpEnd = this.model.highest_post_number === 1 ? true : false;
+ const highestPostNumber = this.model.highest_post_number;
+
+ if (document.getElementById(`post_${highestPostNumber}`)) {
+ // Do nothing when the last post is already rendered.
+ // This ensures the browser handles keyboard shortcuts like End.
+ return;
+ }
DiscourseURL.routeTo(this.get("model.lastPostUrl"), {
skipIfOnScreen: false,
- jumpEnd,
+ jumpEnd: false,
keepFilter: true,
});
}
diff --git a/spec/system/topic_page_spec.rb b/spec/system/topic_page_spec.rb
index aa65c048074..dcba74a1741 100644
--- a/spec/system/topic_page_spec.rb
+++ b/spec/system/topic_page_spec.rb
@@ -86,4 +86,16 @@ describe "Topic page", type: :system do
expect(page).to have_no_css(".topic-admin-menu-content")
end
+
+ context "with End keyboard shortcut" do
+ fab!(:posts) { Fabricate.times(25, :post, topic: topic) }
+
+ it "loads last post" do
+ visit "/t/#{topic.slug}/#{topic.id}/1"
+
+ send_keys(:end)
+
+ expect(find("#post_#{topic.highest_post_number}")).to be_visible
+ end
+ end
end