Kaynağa Gözat

Merge pull request #2376 from overleaf/cmg-no-comment-blur

Stop cancelling a comment on Safari from still creating it

GitOrigin-RevId: b2e6ca77caa9ba318d330f23dd88e04972c7c829
Eric Mc Sween 6 yıl önce
ebeveyn
işleme
1c0dc0a13f

+ 0 - 1
services/web/app/views/project/editor/review-panel.pug

@@ -477,7 +477,6 @@ script(type='text/ng-template', id='addCommentEntryTemplate')
 						ng-keypress="handleCommentKeyPress($event);"
 						ng-keypress="handleCommentKeyPress($event);"
 						placeholder=translate("add_your_comment_here")
 						placeholder=translate("add_your_comment_here")
 						focus-on="comment:new:open"
 						focus-on="comment:new:open"
-						ng-blur="submitNewComment($event)"
 					)
 					)
 				.rp-entry-actions
 				.rp-entry-actions
 					button.rp-entry-button.rp-entry-button-cancel(
 					button.rp-entry-button.rp-entry-button-cancel(

+ 16 - 35
services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js

@@ -1,17 +1,5 @@
-/* eslint-disable
-    max-len,
-    no-return-assign,
-    no-undef,
-*/
-// TODO: This file was created by bulk-decaffeinate.
-// Fix any style issues and re-enable lint.
-/*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
-define(['base'], App =>
+define(['base'], App => {
+  let content = ''
   App.directive('addCommentEntry', () => ({
   App.directive('addCommentEntry', () => ({
     restrict: 'E',
     restrict: 'E',
     templateUrl: 'addCommentEntryTemplate',
     templateUrl: 'addCommentEntryTemplate',
@@ -23,48 +11,41 @@ define(['base'], App =>
     link(scope, element, attrs) {
     link(scope, element, attrs) {
       scope.state = {
       scope.state = {
         isAdding: false,
         isAdding: false,
-        content: ''
+        content: content
       }
       }
 
 
       scope.$on('comment:start_adding', () => scope.startNewComment())
       scope.$on('comment:start_adding', () => scope.startNewComment())
+      scope.$on('$destroy', function() {
+        content = scope.state.content
+      })
 
 
       scope.startNewComment = function() {
       scope.startNewComment = function() {
         scope.state.isAdding = true
         scope.state.isAdding = true
         scope.onStartNew()
         scope.onStartNew()
-        return setTimeout(() => scope.$broadcast('comment:new:open'))
+        setTimeout(() => scope.$broadcast('comment:new:open'))
       }
       }
 
 
       scope.cancelNewComment = function() {
       scope.cancelNewComment = function() {
         scope.state.isAdding = false
         scope.state.isAdding = false
-        return scope.onCancel()
+        scope.state.content = ''
+        scope.onCancel()
       }
       }
 
 
       scope.handleCommentKeyPress = function(ev) {
       scope.handleCommentKeyPress = function(ev) {
         if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
         if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
           ev.preventDefault()
           ev.preventDefault()
           if (scope.state.content.length > 0) {
           if (scope.state.content.length > 0) {
-            return scope.submitNewComment()
+            scope.submitNewComment()
           }
           }
         }
         }
       }
       }
 
 
-      return (scope.submitNewComment = function(event) {
-        // If this is from a blur event from clicking on cancel, ignore it.
-        if (event != null && event.type === 'blur') {
-          if (
-            // Includes relatedTarget workaround for Firefox
-            $(event.relatedTarget).hasClass('rp-entry-button-cancel') ||
-            $(event.originalEvent.explicitOriginalTarget).hasClass(
-              'rp-entry-button-cancel'
-            )
-          ) {
-            return true
-          }
-        }
-
+      scope.submitNewComment = function(event) {
         scope.onSubmit({ content: scope.state.content })
         scope.onSubmit({ content: scope.state.content })
+        content = scope.state.content
         scope.state.isAdding = false
         scope.state.isAdding = false
-        return (scope.state.content = '')
-      })
+        scope.state.content = ''
+      }
     }
     }
-  })))
+  }))
+})