FIX: Use context sensitive "create topic" via keyboard if possible

FIX: Use context sensitive “create topic” via keyboard if possible

diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
index cb0a1be..615949c 100644
--- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
+++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
@@ -196,12 +196,21 @@ export default {
   },
 
   createTopic() {
-    if (this.currentUser && this.currentUser.can_create_topic) {
-      this.container.lookup("controller:composer").open({
-        action: Composer.CREATE_TOPIC,
-        draftKey: Composer.CREATE_TOPIC
-      });
+    if (!(this.currentUser && this.currentUser.can_create_topic)) {
+      return;
     }
+
+    // If the page has a create-topic button, use it for context sensitive attributes like category
+    let $createTopicButton = $("#create-topic");
+    if ($createTopicButton.length) {
+      $createTopicButton.click();
+      return;
+    }
+
+    this.container.lookup("controller:composer").open({
+      action: Composer.CREATE_TOPIC,
+      draftKey: Composer.CREATE_TOPIC
+    });
   },
 
   focusComposer() {

GitHub sha: a518950e

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: