diff --git a/Changelog.md b/Changelog.md index 0f12823e643c6bf88e03862b04308a48b39b865c..df86d8b9b83aeba56cf2b950b04e9a1be3285c60 100644 --- a/Changelog.md +++ b/Changelog.md @@ -46,6 +46,7 @@ If so, please delete it since it will prevent the federation from working proper * Add inviter first and last name in the invitation e-mail [#7484](https://github.com/diaspora/diaspora/pull/7484) * Add markdown editor for comments and conversations [#7482](https://github.com/diaspora/diaspora/pull/7482) * Improve responsive header in desktop version [#7509](https://github.com/diaspora/diaspora/pull/7509) +* Support cmd+enter to submit posts, comments and conversations [#7524](https://github.com/diaspora/diaspora/pull/7524) # 0.6.8.0 diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index d0652e5da06ccc525e97d4ed6c5a4b657c9f429b..0602b3708c75511a904401020c99a563f40894df 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -82,7 +82,7 @@ app.views.CommentStream = app.views.Base.extend({ }, keyDownOnCommentBox: function(evt) { - if(evt.which === Keycodes.ENTER && evt.ctrlKey) { + if (evt.which === Keycodes.ENTER && (evt.metaKey || evt.ctrlKey)) { this.$("form").submit(); return false; } diff --git a/app/assets/javascripts/app/views/conversations_form_view.js b/app/assets/javascripts/app/views/conversations_form_view.js index df156b0a74da018614487a8faf9537b6042fa38c..a28b6d42651ba52b4d5b8db98af9c478836ffcf6 100644 --- a/app/assets/javascripts/app/views/conversations_form_view.js +++ b/app/assets/javascripts/app/views/conversations_form_view.js @@ -74,7 +74,7 @@ app.views.ConversationsForm = app.views.Base.extend({ }, keyDown: function(evt) { - if (evt.which === Keycodes.ENTER && evt.ctrlKey) { + if (evt.which === Keycodes.ENTER && (evt.metaKey || evt.ctrlKey)) { $(evt.target).parents("form").submit(); } }, diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index 211153198e402be2ab40c16f38412d4681b71ecb..baffa26da18a07dab4ad0e4f4a48a4b5b5bec4b5 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -352,7 +352,7 @@ app.views.Publisher = Backbone.View.extend({ }, keyDown : function(evt) { - if(evt.which === Keycodes.ENTER && evt.ctrlKey) { + if (evt.which === Keycodes.ENTER && (evt.metaKey || evt.ctrlKey)) { this.$("form").submit(); this.open(); return false; diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index 38b3a95875acf1981b01ad5f080abb2a45b15ad6..7d058c589ece231ef4273d4404fbb8d210b7c816 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -410,23 +410,34 @@ describe("app.views.CommentStream", function(){ submitCallback = jasmine.createSpy().and.returnValue(false); }); - it("should not submit the form when enter key is pressed", function(){ + it("should not submit the form without the ctrl or cmd keys", function() { this.view.render(); var form = this.view.$("form"); form.submit(submitCallback); - var e = $.Event("keydown", { which: Keycodes.ENTER, ctrlKey: false }); + var e = $.Event("keydown", {which: Keycodes.ENTER, ctrlKey: false, metaKey: false}); this.view.keyDownOnCommentBox(e); expect(submitCallback).not.toHaveBeenCalled(); }); - it("should submit the form when enter is pressed with ctrl", function(){ + it("should submit the form when enter is pressed with ctrl", function() { this.view.render(); var form = this.view.$("form"); form.submit(submitCallback); - var e = $.Event("keydown", { which: Keycodes.ENTER, ctrlKey: true }); + var e = $.Event("keydown", {which: Keycodes.ENTER, ctrlKey: true}); + this.view.keyDownOnCommentBox(e); + + expect(submitCallback).toHaveBeenCalled(); + }); + + it("should submit the form when enter is pressed with cmd", function() { + this.view.render(); + var form = this.view.$("form"); + form.submit(submitCallback); + + var e = $.Event("keydown", {which: Keycodes.ENTER, metaKey: true}); this.view.keyDownOnCommentBox(e); expect(submitCallback).toHaveBeenCalled(); diff --git a/spec/javascripts/app/views/conversations_form_view_spec.js b/spec/javascripts/app/views/conversations_form_view_spec.js index 959955e6d002b705963c20e5ec496922faefa6b4..b0d06535094c8a350affa3a844d5f7f35eca066b 100644 --- a/spec/javascripts/app/views/conversations_form_view_spec.js +++ b/spec/javascripts/app/views/conversations_form_view_spec.js @@ -164,9 +164,16 @@ describe("app.views.ConversationsForm", function() { expect(this.submitCallback).toHaveBeenCalled(); }); - it("shouldn't submit the form without the ctrl key", function() { + it("should submit the form with cmd+enter", function() { $("#new-conversation").submit(this.submitCallback); - var e = $.Event("keydown", {which: Keycodes.ENTER, ctrlKey: false}); + var e = $.Event("keydown", {which: Keycodes.ENTER, metaKey: true}); + $("#new-message-text").trigger(e); + expect(this.submitCallback).toHaveBeenCalled(); + }); + + it("shouldn't submit the form without the ctrl or cmd key", function() { + $("#new-conversation").submit(this.submitCallback); + var e = $.Event("keydown", {which: Keycodes.ENTER, ctrlKey: false, metaKey: false}); $("#new-message-text").trigger(e); expect(this.submitCallback).not.toHaveBeenCalled(); }); @@ -185,9 +192,16 @@ describe("app.views.ConversationsForm", function() { expect(this.submitCallback).toHaveBeenCalled(); }); - it("shouldn't submit the form without the ctrl key", function() { + it("should submit the form with cmd+enter", function() { + $("#response-message").submit(this.submitCallback); + var e = $.Event("keydown", {which: Keycodes.ENTER, metaKey: true}); + $("#response-message-text").trigger(e); + expect(this.submitCallback).toHaveBeenCalled(); + }); + + it("shouldn't submit the form without the ctrl or cmd key", function() { $("#response-message").submit(this.submitCallback); - var e = $.Event("keydown", {which: Keycodes.ENTER, ctrlKey: false}); + var e = $.Event("keydown", {which: Keycodes.ENTER, ctrlKey: false, metaKey: false}); $("#response-message-text").trigger(e); expect(this.submitCallback).not.toHaveBeenCalled(); }); diff --git a/spec/javascripts/app/views/publisher_view_spec.js b/spec/javascripts/app/views/publisher_view_spec.js index e286c3cf6dd5f981ef4d03625d6e5458a761e2e9..1a8b4a3bf827f5ef497d76b20bc7d4785e564edc 100644 --- a/spec/javascripts/app/views/publisher_view_spec.js +++ b/spec/javascripts/app/views/publisher_view_spec.js @@ -250,6 +250,19 @@ describe("app.views.Publisher", function() { expect(submitCallback).toHaveBeenCalled(); expect($(this.view.el)).not.toHaveClass("closed"); }); + + it("should submit the form when cmd+enter is pressed", function() { + this.view.render(); + var form = this.view.$("form"); + var submitCallback = jasmine.createSpy().and.returnValue(false); + form.submit(submitCallback); + + var e = $.Event("keydown", {which: Keycodes.ENTER, metaKey: true}); + this.view.keyDown(e); + + expect(submitCallback).toHaveBeenCalled(); + expect($(this.view.el)).not.toHaveClass("closed"); + }); }); describe("tryClose", function() {