From b5495b8e9cd71dea8387d563fd19a39473027e29 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 19 Jun 2020 11:17:18 +1000 Subject: [PATCH] FIX: Do not incorrectly add topic bookmark on Escape (#10088) * The first post was showing as bookmarked incorrectly after pressing f to open the topic modal then pressing escape to cancel without saving, because the closeWithoutSaving option was not being respected. * Also re-introduce the enter shortcut when the name input is focused to saveAndClose the bookmark modal by pressing enter. --- app/assets/javascripts/discourse/app/models/topic.js | 5 ++++- .../javascripts/discourse/app/templates/modal/bookmark.hbs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js index 4f5305fec63..b4a69c33c75 100644 --- a/app/assets/javascripts/discourse/app/models/topic.js +++ b/app/assets/javascripts/discourse/app/models/topic.js @@ -430,8 +430,11 @@ const Topic = RestModel.extend({ return this.firstPost().then(firstPost => { const toggleBookmarkOnServer = () => { if (bookmark) { - return firstPost.toggleBookmark().then(() => { + return firstPost.toggleBookmark().then(opts => { this.set("bookmarking", false); + if (opts.closedWithoutSaving) { + return; + } return this.afterTopicBookmarked(firstPost); }); } else { diff --git a/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs b/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs index 615ae16b07b..d3811ac9abd 100644 --- a/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs +++ b/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs @@ -9,7 +9,7 @@ {{/if}}
- {{input id="bookmark-name" value=model.name name="bookmark-name" class="bookmark-name" placeholder=(i18n "post.bookmarks.name_placeholder")}} + {{input id="bookmark-name" value=model.name name="bookmark-name" class="bookmark-name" enter=(action "saveAndClose") placeholder=(i18n "post.bookmarks.name_placeholder")}} {{d-button icon="cog" action=(action "toggleOptionsPanel") class="bookmark-options-button"}}