Changeset 58075 in webkit


Ignore:
Timestamp:
Apr 22, 2010 2:12:19 AM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-04-22 Adam Barth <abarth@webkit.org>

Reviewed by Darin Adler.

Hack up PrettyDiff to allow line-by-line comments
https://bugs.webkit.org/show_bug.cgi?id=37886

Admittedly a bit of a hack, this is a basic line-by-line editor we can
play with thanks to Andrew Scherkus. It's meant to integrate with the
"review" page at bugs.webkit.org.

I changed a few things from Andrew's original version:
1) Trigger text boxes on single click to make iPhone/iPad reviewing
easier.
2) Clear the main text box on load.
3) Reference a version of prototype.js on bugs.webkit.org.

  • PrettyPatch/PrettyPatch.rb:
  • prototype.js: Added.
Location:
trunk/BugsSite
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BugsSite/ChangeLog

    r55080 r58075  
     12010-04-22  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Hack up PrettyDiff to allow line-by-line comments
     6        https://bugs.webkit.org/show_bug.cgi?id=37886
     7
     8        Admittedly a bit of a hack, this is a basic line-by-line editor we can
     9        play with thanks to Andrew Scherkus.  It's meant to integrate with the
     10        "review" page at bugs.webkit.org.
     11
     12        I changed a few things from Andrew's original version:
     13        1) Trigger text boxes on single click to make iPhone/iPad reviewing
     14        easier.
     15        2) Clear the main text box on load.
     16        3) Reference a version of prototype.js on bugs.webkit.org.
     17
     18        * PrettyPatch/PrettyPatch.rb:
     19        * prototype.js: Added.
     20
    1212010-02-22  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
    222
  • trunk/BugsSite/PrettyPatch/PrettyPatch.rb

    r53700 r58075  
    183183    text-decoration: none;
    184184}
     185
     186/* Support for inline comments */
     187.comment {
     188  border: 1px width solid red;
     189  font-family: monospace;
     190}
     191
     192.comment textarea {
     193  width: 100%;
     194  height: 6em;
     195}
     196
     197.submitted {
     198  font-weight: bold;
     199  color: red;
     200}
    185201</style>
     202<script src="https://bugs.webkit.org/prototype.js"></script>
     203<script>
     204// Code to support inline comments in bugs.webkit.org.
     205function getSubmitTextArea() {
     206  // Note that this only works when running on same domain.
     207  return parent.frames[1].document.getElementsByTagName("textarea")[0];
     208}
     209
     210function onLineClicked(e) {
     211  // Find the right line div.
     212  // FIXME: why does a click event on my div get intercepted
     213  // by a span or even document element :(
     214  var line = e.target;
     215  while (true) {
     216    if (line == document)
     217      return;
     218    if (line.getAttribute("class").substr(0, 4) == "Line")
     219      break;
     220    line = line.up();
     221  }
     222
     223  if (line.hasComment)
     224    return;
     225  line.hasComment = true;
     226
     227  var lineFrom = line.select("[class='from lineNumber']")[0].innerHTML;
     228  var lineTo = line.select("[class='to lineNumber']")[0].innerHTML;
     229  var lineText = line.select("[class='text']")[0].innerHTML;
     230
     231  line.insert({after:
     232      "<div class='comment'>" +
     233      "<textarea></textarea>" +
     234      "<button onclick='onCommentSubmit(this.up())'>Add</button>" +
     235      "<button onclick='onCommentCancel(this.up())'>Cancel</button>" +
     236      "</div>"});
     237
     238  var comment = line.next();
     239  var textarea = comment.select("textarea")[0];
     240  textarea.focus();
     241}
     242
     243function onCommentSubmit(comment) {
     244  var textarea = comment.select("textarea")[0];
     245  var buttons = comment.select("button");
     246  var commentText = textarea.value;
     247
     248  var line = comment.previous();
     249  line.hasComment = false
     250  var lineFrom = line.select("[class='from lineNumber']")[0].textContent;
     251  var lineTo = line.select("[class='to lineNumber']")[0].textContent;
     252  var lineText = line.select("[class='text']")[0].textContent;
     253  var filename = comment.up().up().select("h1")[0].down().textContent;
     254
     255  var snippet = filename + ":" + lineTo + "\n +  " + lineText + "\n" + commentText + "\n\n";
     256
     257  // Remove all the crap.
     258  textarea.remove();
     259  buttons[0].remove();
     260  buttons[1].remove();
     261
     262  // Insert a non-editable form of our comment.
     263  comment.insert("<pre>" + commentText + "</pre>");
     264  comment.setAttribute("class", "comment submitted");
     265
     266  // Update the submission text area.
     267  var submission = getSubmitTextArea();
     268  submission.value = submission.value + snippet;
     269}
     270
     271function onCommentCancel(comment) {
     272  var line = comment.previous();
     273  line.hasComment = false
     274  comment.remove();
     275}
     276
     277if (top !== window) {
     278  window.addEventListener("load", function () {
     279    var lines = $$("div[class~='Line']");
     280    for (var i = 0; i < lines.length; ++i) {
     281      lines[i].addEventListener("click", onLineClicked, false);
     282    }
     283  }, false);
     284
     285  parent.addEventListener("load", function () {
     286    // Remove the full diff from the submit text area.
     287    return parent.frames[1].document.getElementsByTagName("textarea")[0].value = "";
     288  }, false);
     289}
     290</script>
    186291EOF
    187292
Note: See TracChangeset for help on using the changeset viewer.