From 27f97070584268b4048a283b452683d18471f724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 8 Oct 2018 21:35:17 +0200 Subject: [PATCH] Allow submit of comments using shift+enter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- js/directive/contenteditable.js | 18 ++++++++++++++---- templates/part.card.activity.html | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/js/directive/contenteditable.js b/js/directive/contenteditable.js index 8ea80dda8..b3d334120 100644 --- a/js/directive/contenteditable.js +++ b/js/directive/contenteditable.js @@ -22,10 +22,13 @@ import app from '../app/App'; -app.directive("ngContenteditable", function($compile) { +app.directive('ngContenteditable', function($compile) { return { - require: "ngModel", + require: 'ngModel', restrict: 'A', + scope: { + submit: '&ngSubmit' + }, link: function(scope, element, attrs, ngModel) { //read the text typed in the div (syncing model with the view) @@ -37,13 +40,20 @@ app.directive("ngContenteditable", function($compile) { //$render is invoked when the modelvalue differs from the viewvalue //see documentation: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController# ngModel.$render = function() { - element.html(ngModel.$viewValue || ""); + element.html(ngModel.$viewValue || ''); }; //do this whenever someone starts typing - element.bind("blur keyup change", function() { + element.bind('blur keyup change', function(event) { scope.$apply(read); }); + + element.bind('keydown', function(event) { + if(event.which == '13' && event.shiftKey) { + scope.submit(); + } + }); + } }; }); diff --git a/templates/part.card.activity.html b/templates/part.card.activity.html index 065e83d5d..d4c1fafc2 100644 --- a/templates/part.card.activity.html +++ b/templates/part.card.activity.html @@ -4,10 +4,10 @@
{{ $ctrl.currentUser.displayName }}
-
-
+ +
+ value="" title="" data-original-title="Post" ng-if="!$ctrl.status.commentCreateLoading">