diff --git a/Changelog.md b/Changelog.md index fff3fc383..9a2d8affd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -115,7 +115,6 @@ by them self. * Remove unnecessary dotted CSS borders. [#2940](https://github.com/diaspora/diaspora/issues/2940) * Fix default image url in profiles table. [#3795](https://github.com/diaspora/diaspora/issues/3795) * Fix mobile buttons are only clickable when scrolled to the top. [#4102](https://github.com/diaspora/diaspora/issues/4102) -* Fix regression in bookmarklet causing uneditable post contents. [#4057](https://github.com/diaspora/diaspora/issues/4057) ## Features @@ -127,7 +126,7 @@ by them self. * Add multiphoto for mobile post. [#4065](https://github.com/diaspora/diaspora/issues/4065) * Add hotkeys to navigate in stream [#4089](https://github.com/diaspora/diaspora/pull/4089) * Add a brief explanatory text about external services connections to services index page [#3064](https://github.com/diaspora/diaspora/issues/3064) -* Add a preview for posts in the stream [#4099](https://github.com/diaspora/diaspora/issues/4099) +* Shift + Enter will submit the comment. [#4096](github.com/diaspora/diaspora/pull/4096) # 0.0.3.4 diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index c2e74b120..7f242ddb8 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -5,6 +5,7 @@ app.views.CommentStream = app.views.Base.extend({ className : "comment_stream", events: { + "keydown .comment_box": "keyDownOnCommentBox", "submit form": "createComment", "focus .comment_box": "commentTextareaFocused", "click .toggle_post_comments": "expandComments" @@ -51,6 +52,13 @@ app.views.CommentStream = app.views.Base.extend({ } }, + keyDownOnCommentBox: function(evt) { + if(evt.keyCode == 13 && evt.shiftKey) { + this.$("form").submit() + return false; + } + }, + appendComment: function(comment) { // Set the post as the comment's parent, so we can check // on post ownership in the Comment view. diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index e78990b82..994acf2d9 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -80,4 +80,32 @@ describe("app.views.CommentStream", function(){ expect(this.view.$("textarea").val()).toEqual("great post!"); }) }) + + describe("pressing a key when typing on the new comment box", function(){ + it("should not submit the form when enter key is pressed", function(){ + this.view.render(); + var form = this.view.$("form") + var submitCallback = jasmine.createSpy().andReturn(false);form.submit(submitCallback); + + var e = $.Event("keydown", { keyCode: 13 }); + e.shiftKey = false; + this.view.keyDownOnCommentBox(e); + + expect(submitCallback).not.toHaveBeenCalled(); + }) + + it("should submit the form when enter is pressed with shift", function(){ + this.view.render(); + var form = this.view.$("form") + var submitCallback = jasmine.createSpy().andReturn(false); + form.submit(submitCallback); + + var e = $.Event("keydown", { keyCode: 13 }); + e.shiftKey = true; + this.view.keyDownOnCommentBox(e); + + expect(submitCallback).toHaveBeenCalled(); + }) + }) + })