• 
      

    Double-clicking to Add a Comment in the Diff View Discards Any Comments Made

    Review Request #6340 — Created Sept. 19, 2014 and submitted

    Information

    Review Board
    master
    b8fd086...

    Reviewers

    When double-clicking on a line number to add a comment in the diff view, this is registered as two seperate clicks. The comment dialog opens on the first click, and then on the second click the dialog is closed, the comment is deleted, and then the dialog is reopened (but no new comment is created). So, clicking save would not save the comment.

    To solve this:
    Before the comment dialog is shown, first check to see if there is already a comment dialog active. If there is, and it is a comment dialog for the same block as the one that is about to be shown, then don't show a new comment dialog (keep the old one as it displays the same comment). A double-click is registered as two clicks for the same comment block, and so the first click will show the dialog, and the second will do nothing.

    Tried all of the following (in Firefox, Chrome):
    - Adding comment by double-clicking on a line number and comment flag
    - Adding comment by single-clicking on a line number and comment flag
    - Adding comment by selecting a range of lines

    All JavaScript unit tests passed.

    Description From Last Updated

    var statements must go to the very top of the function. While JavaScript does allow you to write them anywhere, …

    chipx86chipx86

    No need for the parens around the comparisons.

    chipx86chipx86

    This is actually global state that will apply to every single instance of an AbstractReviewableView. Instead, you want to set …

    chipx86chipx86

    It's safe to just do a comparison without first checking if it's truthy. If it's falsy, then it'll simply fail.

    chipx86chipx86

    The ) { must go on the previous line.

    chipx86chipx86

    listenTo doesn't take that last parameter (this). Instead, that's implied by using listenTo.

    chipx86chipx86
    reviewbot
    1. Tool: PEP8 Style Checker
      Ignored Files:
          reviewboard/static/rb/js/views/commentDialogView.js
      
      
      
      Tool: Pyflakes
      Ignored Files:
          reviewboard/static/rb/js/views/commentDialogView.js
      
      
    2. 
        
    dkus
    chipx86
    1. This is a good start, but it'll break on non-diffs. We support commenting on all kinds of things, such as images or PDFs (if using our Power Pack extension).

      What I'd suggest doing instead is updating views/abstractReviewableView.js's showCommentDlg function, which is used for all reviewable things, like the diff viewer. You can have it keep a this._activeCommentBlock state (set and cleared at the same times as this.commentDlg). If it's set and it directly matches (simple ===) the one provided to the function, it can just simply return.

      I think that will work, and the nice thing is that it should fix this for all reviewable pages.

      I do have some general notes on style guidelines, while I'm here.

    2. Show all issues

      var statements must go to the very top of the function. While JavaScript does allow you to write them anywhere, internally it "hoists" the declarations to the top of the function, which can result in odd behavior in certain cases.

      To help minify, we also only ever use one var per function, like this:

      var foo = 1,
          bar = 2,
          s = '';
      
    3. Show all issues

      No need for the parens around the comparisons.

    4. 
        
    dkus
    reviewbot
    1. Tool: Pyflakes
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
      
      Tool: PEP8 Style Checker
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
    2. 
        
    dkus
    chipx86
    1. 
        
    2. Show all issues

      This is actually global state that will apply to every single instance of an AbstractReviewableView. Instead, you want to set this in initialize.

    3. Show all issues

      It's safe to just do a comparison without first checking if it's truthy. If it's falsy, then it'll simply fail.

    4. Show all issues

      The ) { must go on the previous line.

    5. 
        
    dkus
    reviewbot
    1. Tool: PEP8 Style Checker
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
      
      Tool: Pyflakes
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
    2. 
        
    dkus
    reviewbot
    1. Tool: PEP8 Style Checker
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
      
      Tool: Pyflakes
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
    2. 
        
    dkus
    chipx86
    1. Looking good! One last thing.

    2. Show all issues

      listenTo doesn't take that last parameter (this). Instead, that's implied by using listenTo.

    3. 
        
    dkus
    reviewbot
    1. Tool: Pyflakes
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
      
      Tool: PEP8 Style Checker
      Ignored Files:
          reviewboard/static/rb/js/views/abstractReviewableView.js
      
      
    2. 
        
    chipx86
    1. Ship It!

    2. 
        
    dkus
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-2.0.x (aac6bda)