From 7b3b05f22997c894c6587d8141ea218308acb22f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 21 Oct 2020 08:55:58 +1100 Subject: [PATCH] FEATURE: CTRL-SHIFT-ENTER and SHIFT-Click do not scroll on post (#10965) This allows for an advanced feature where hitting control on click or CTRL-SHIFT-ENTER will lead to a post being made but the browser not to scroll to the end. --- .../discourse/app/components/d-button.js | 15 ++++++++++++--- .../discourse/app/controllers/composer.js | 9 +++++---- .../discourse/app/mixins/key-enter-escape.js | 2 +- .../discourse/app/templates/composer.hbs | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/d-button.js b/app/assets/javascripts/discourse/app/components/d-button.js index b053b41867a..20f76b8ccbf 100644 --- a/app/assets/javascripts/discourse/app/components/d-button.js +++ b/app/assets/javascripts/discourse/app/components/d-button.js @@ -17,6 +17,7 @@ export default Component.extend({ translatedLabel: null, ariaLabel: null, translatedAriaLabel: null, + forwardEvent: false, isLoading: computed({ set(key, value) { @@ -89,7 +90,7 @@ export default Component.extend({ return computedLabel; }, - click() { + click(event) { let { action } = this; if (action) { @@ -98,9 +99,17 @@ export default Component.extend({ // There is already a warning in the console. this.sendAction("action", this.actionParam); } else if (typeof action === "object" && action.value) { - action.value(this.actionParam); + if (this.forwardEvent) { + action.value(this.actionParam, event); + } else { + action.value(this.actionParam); + } } else if (typeof this.action === "function") { - action(this.actionParam); + if (this.forwardEvent) { + action(this.actionParam, event); + } else { + action(this.actionParam); + } } } diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js index f79b5b09e2b..c2fd4ba2385 100644 --- a/app/assets/javascripts/discourse/app/controllers/composer.js +++ b/app/assets/javascripts/discourse/app/controllers/composer.js @@ -547,8 +547,8 @@ export default Controller.extend({ this.cancelComposer(differentDraftContext); }, - save() { - this.save(); + save(ignore, event) { + this.save(false, { jump: !(event && event.shiftKey) }); }, displayEditReason() { @@ -626,7 +626,7 @@ export default Controller.extend({ disableSubmit: or("model.loading", "isUploading"), - save(force) { + save(force, options = {}) { if (this.disableSubmit) { return; } @@ -775,7 +775,8 @@ export default Controller.extend({ this.currentUser.set("any_posts", true); const post = result.target; - if (post && !staged) { + + if (post && !staged && options.jump !== false) { DiscourseURL.routeTo(post.url, { skipIfOnScreen: true }); } }) diff --git a/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js b/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js index 52dc0509f9c..dfa120a5a78 100644 --- a/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js +++ b/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js @@ -14,7 +14,7 @@ export default { // // iPad physical keyboard does not offer Command or Control detection // so use ALT-ENTER - this.save(); + this.save(undefined, e); return false; } }, diff --git a/app/assets/javascripts/discourse/app/templates/composer.hbs b/app/assets/javascripts/discourse/app/templates/composer.hbs index ded30ce02a8..0d53c253b14 100644 --- a/app/assets/javascripts/discourse/app/templates/composer.hbs +++ b/app/assets/javascripts/discourse/app/templates/composer.hbs @@ -135,6 +135,7 @@ {{composer-save-button action=(action "save") icon=saveIcon label=saveLabel + forwardEvent=true disableSubmit=disableSubmit}} {{#if site.mobileView}}