diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index d0652e5da..0602b3708 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 df156b0a7..a28b6d426 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 211153198..baffa26da 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 38b3a9587..7d058c589 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 959955e6d..b0d065350 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, ctrlKey: false}); + 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, 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 e286c3cf6..1a8b4a3bf 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() {