support cmd+enter for post submission

This commit is contained in:
ivan sebastian 2017-08-11 22:15:02 +07:00
parent 280a9e2023
commit b154e9d7f9
6 changed files with 49 additions and 11 deletions

View file

@ -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;
}

View file

@ -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();
}
},

View file

@ -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;

View file

@ -410,12 +410,12 @@ 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();
@ -431,5 +431,16 @@ describe("app.views.CommentStream", function(){
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();
});
});
});

View file

@ -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();
});

View file

@ -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() {