A platform for community discussion. Free, open, simple.
FIX: Dismiss new keyboard shortcut not working (#13430)
Martin Brennan7f916ad06d16
diff --git a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.jsindex 3ad6a9cc242..7c80fb42772 100644--- a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js+++ b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js@@ -86,8 +86,8 @@ const DEFAULT_BINDINGS = {t: { postAction: "replyAsNewTopic" },u: { handler: "goBack", anonymous: true },"x r": {- click: "#dismiss-new,#dismiss-new-top,#dismiss-posts,#dismiss-posts-top",- }, // dismiss new/posts+ click: "#dismiss-new-bottom,#dismiss-new-top",+ }, // dismiss new"x t": { click: "#dismiss-topics-bottom,#dismiss-topics-top" }, // dismiss topics};@@ -549,7 +549,11 @@ export default {// If effective, prevent default.e.preventDefault();}- $sel.click();++ // If there is more than one match for the selector, just click+ // the first one, we don't want to click multiple things from one+ // shortcut.+ $sel[0].click();});},diff --git a/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js b/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.jsindex bb316a1a923..9ba4298aef6 100644--- a/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js@@ -82,6 +82,7 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {test("dismiss unread from top and bottom button", async function (assert) {await visit("/unread");+ assert.ok(exists("#dismiss-topics-top"));await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));await triggerKeyEvent(document, "keypress", "t".charCodeAt(0));assert.ok(exists("#dismiss-read-confirm"));@@ -98,7 +99,10 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {let originalTopics = [...topicList.topic_list.topics];topicList.topic_list.topics = [topicList.topic_list.topics[0]];+ // visit root first so topic list starts fresh+ await visit("/");await visit("/unread");+ assert.notOk(exists("#dismiss-topics-top"));await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));await triggerKeyEvent(document, "keypress", "t".charCodeAt(0));assert.ok(exists("#dismiss-read-confirm"));@@ -115,6 +119,7 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {test("dismiss new from top and bottom button", async function (assert) {await visit("/new");+ assert.ok(exists("#dismiss-new-top"));await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));await triggerKeyEvent(document, "keypress", "r".charCodeAt(0));assert.equal(resetNewCalled, 1);@@ -125,7 +130,10 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {let originalTopics = [...topicList.topic_list.topics];topicList.topic_list.topics = [topicList.topic_list.topics[0]];+ // visit root first so topic list starts fresh+ await visit("/");await visit("/new");+ assert.notOk(exists("#dismiss-new-top"));await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));await triggerKeyEvent(document, "keypress", "r".charCodeAt(0));assert.equal(resetNewCalled, 2);@@ -133,4 +141,15 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {// restore the original topic listtopicList.topic_list.topics = originalTopics;});++ test("click event not fired twice when both dismiss buttons are present", async function (assert) {+ await visit("/new");+ assert.ok(exists("#dismiss-new-top"));+ assert.ok(exists("#dismiss-new-bottom"));++ await triggerKeyEvent(document, "keypress", "x".charCodeAt(0));+ await triggerKeyEvent(document, "keypress", "r".charCodeAt(0));++ assert.equal(resetNewCalled, 1);+ });});