From 96982ca2bcdec0ed119ce3cb5a8ecf7a92577f51 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 21 Dec 2021 19:53:07 +0100 Subject: [PATCH] FIX: gives composer options to post:highlight trigger (#15384) This change allows to prevent page jump, when jump is prevented, due to highlightPost causing a `focus()`. --- .../discourse/app/components/discourse-topic.js | 7 +++++-- .../javascripts/discourse/app/controllers/composer.js | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/discourse-topic.js b/app/assets/javascripts/discourse/app/components/discourse-topic.js index d5daaca8397..87a5cbb1397 100644 --- a/app/assets/javascripts/discourse/app/components/discourse-topic.js +++ b/app/assets/javascripts/discourse/app/components/discourse-topic.js @@ -1,3 +1,4 @@ +import { isBlank } from "@ember/utils"; import { later, schedule, scheduleOnce, throttle } from "@ember/runloop"; import AddArchetypeClass from "discourse/mixins/add-archetype-class"; import ClickTrack from "discourse/lib/click-track"; @@ -48,8 +49,10 @@ export default Component.extend( } }, - _highlightPost(postNumber) { - scheduleOnce("afterRender", null, highlightPost, postNumber); + _highlightPost(postNumber, options = {}) { + if (isBlank(options.jump) || options.jump !== false) { + scheduleOnce("afterRender", null, highlightPost, postNumber); + } }, _hideTopicInHeader() { diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js index 3fa65a4dd53..04b46549b64 100644 --- a/app/assets/javascripts/discourse/app/controllers/composer.js +++ b/app/assets/javascripts/discourse/app/controllers/composer.js @@ -894,7 +894,11 @@ export default Controller.extend({ if (result.responseJson.action === "create_post") { this.appEvents.trigger("composer:created-post"); - this.appEvents.trigger("post:highlight", result.payload.post_number); + this.appEvents.trigger( + "post:highlight", + result.payload.post_number, + options + ); } if (this.get("model.draftKey") === Composer.NEW_TOPIC_KEY) {