Merge pull request #7524 from ivantedja/7273-cmd-enter-submit

support cmd+enter for post submission
parents 53f05eff b154e9d7
......@@ -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
......
......@@ -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;
}
......
......@@ -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();
}
},
......
......@@ -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;
......
......@@ -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();
......
......@@ -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();
});
......
......@@ -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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment