diff --git a/src/main/twirl/helper/diff.scala.html b/src/main/twirl/helper/diff.scala.html
index 0a73e64..1f3bbef 100644
--- a/src/main/twirl/helper/diff.scala.html
+++ b/src/main/twirl/helper/diff.scala.html
@@ -118,6 +118,7 @@
});
function renderDiffs(viewType){
+ window.viewType = viewType;
@diffs.zipWithIndex.map { case (diff, i) =>
@if(diff.newContent != None || diff.oldContent != None){
if($('#oldText-@i').length > 0){
@@ -126,26 +127,43 @@
}
}
@if(showLineNotes){
+ function getInlineContainer(where) {
+ if (viewType == 0) {
+ if (where === 'new') {
+ return $('
|
');
+ } else if (where === 'old') {
+ return $(' |
');
+ }
+ }
+ return $('
');
+ }
$('.inline-comment').each(function(i, v) {
var $v = $(v), filename = $v.attr('filename'),
- oldline = $v.attr('oldline'), newline = $v.attr('newline'),
- tmp = $(' |
');
- tmp.children('td').html($(this).clone().show());
+ oldline = $v.attr('oldline'), newline = $v.attr('newline');
if (typeof $('#show-notes')[0] !== 'undefined' && !$('#show-notes')[0].checked) {
$(this).hide();
}
if (typeof oldline !== 'undefined') {
- $('table[filename="' + filename + '"]').find('table.inlinediff').find('.oldline').filter(function() {
- return new RegExp('^' + oldline + '$').test($(this).text());
+ var tmp;
+ if (typeof newline !== 'undefined') {
+ tmp = getInlineContainer();
+ } else {
+ tmp = getInlineContainer('old');
+ }
+ tmp.children('td:first').html($(this).clone().show());
+ $('table[filename="' + filename + '"]').find('table.diff').find('.oldline').filter(function() {
+ return new RegExp('^' + oldline + '[\\+]*$').test($(this).text());
}).parent().nextAll(':not(.not-diff):first').before(tmp);
} else {
- $('table[filename="' + filename + '"]').find('table.inlinediff').find('.newline').filter(function() {
+ var tmp = getInlineContainer('new');
+ tmp.children('td:last').html($(this).clone().show());
+ $('table[filename="' + filename + '"]').find('table.diff').find('.newline').filter(function() {
return new RegExp('^' + newline + '\\+$').test($(this).text());
}).parent().nextAll(':not(.not-diff):first').before(tmp);
}
});
@if(hasWritePermission) {
- $('table.diff tr').hover(
+ $('table.diff th').hover(
function() {
$(this).find('b').css('display', 'inline-block');
},
@@ -153,32 +171,54 @@
$(this).find('b').css('display', 'none');
}
);
- $('.add-comment').click(function() {
- var $this = $(this),
- $tr = $(this).closest('tr');
- if (!$tr.nextAll(':not(.not-diff):first').prev().hasClass('inline-comment-form')) {
- var commitId = $(this).closest('.table-bordered').attr('commitId'),
- fileName = $(this).closest('.table-bordered').attr('fileName'),
- oldLineNumber = $(this).closest('.newline').prev('.oldline').text(),
- newLineNumber = $(this).closest('.newline').clone().children().remove().end().text(),
- url = '@url(repository)/commit/' + commitId + '/comment/_form?fileName=' + fileName @if(issueId.isDefined){+ '&issueId=@issueId.get'}
- if (!isNaN(oldLineNumber) && oldLineNumber != null && oldLineNumber !== '') {
- url += ('&oldLineNumber=' + oldLineNumber)
+ $('table.diff td').hover(
+ function() {
+ $(this).prev('th').find('b').css('display', 'inline-block');
+ },
+ function() {
+ $(this).prev('th').find('b').css('display', 'none');
}
- if (!isNaN(newLineNumber) && newLineNumber != null && newLineNumber !== '') {
- url += ('&newLineNumber=' + newLineNumber)
- }
- $.get(
- url,
- {
- dataType : 'html'
- },
- function(responseContent) {
- $this.hide();
- var tmp = $('');
- tmp.children('td').html(responseContent);
- $tr.nextAll(':not(.not-diff):first').before(tmp);
- });
+ );
+ $('.add-comment').click(function() {
+ var $this = $(this),
+ $tr = $this.closest('tr');
+ if (!$tr.nextAll(':not(.not-diff):first').prev().hasClass('inline-comment-form')) {
+ var commitId = $this.closest('.table-bordered').attr('commitId'),
+ fileName = $this.closest('.table-bordered').attr('fileName'),
+ oldLineNumber, newLineNumber = $this.closest('.newline').clone().children().remove().end().text(),
+ url = '@url(repository)/commit/' + commitId + '/comment/_form?fileName=' + fileName @if(issueId.isDefined){+ '&issueId=@issueId.get'};
+ if (viewType == 0) {
+ oldLineNumber = $this.closest('.oldline').clone().children().remove().end().text();
+ } else {
+ oldLineNumber = $this.closest('tr').find('.oldline').text();
+ }
+ if (!isNaN(oldLineNumber) && oldLineNumber) {
+ url += ('&oldLineNumber=' + oldLineNumber)
+ }
+ if (!isNaN(newLineNumber) && newLineNumber) {
+ url += ('&newLineNumber=' + newLineNumber)
+ }
+ $.get(
+ url,
+ {
+ dataType : 'html'
+ },
+ function(responseContent) {
+ $this.hide();
+ var tmp;
+ if (!isNaN(oldLineNumber) && oldLineNumber) {
+ if (!isNaN(newLineNumber) && newLineNumber) {
+ tmp = getInlineContainer();
+ } else {
+ tmp = getInlineContainer('old');
+ }
+ } else {
+ tmp = getInlineContainer('new');
+ }
+ tmp.addClass('inline-comment-form').children('.comment-box-container').html(responseContent);
+ $tr.nextAll(':not(.not-diff):first').before(tmp);
+ }
+ );
}
});
$('table.diff').on('click', '.btn-default', function() {
diff --git a/src/main/twirl/repo/commentform.scala.html b/src/main/twirl/repo/commentform.scala.html
index edca519..dd1f715 100644
--- a/src/main/twirl/repo/commentform.scala.html
+++ b/src/main/twirl/repo/commentform.scala.html
@@ -47,7 +47,17 @@
type: 'POST',
data: param
}).done(function(data) {
- $form.closest('tr').removeClass('inline-comment-form').find('td').html(' | ').html(data);
+ var tmp;
+ if (window.viewType == 0) {
+ tmp = '@(oldLineNumber, newLineNumber) match {
+ case (Some(_), None) => { | }
+ case (None, Some(_)) => { | }
+ case _ => {}
+ }'
+ } else {
+ tmp = ''
+ }
+ $form.closest('tr').removeClass('inline-comment-form').html(tmp).find('.comment-box-container').html(data);
$('#comment-list').append(data);
if (typeof $('#show-notes')[0] !== 'undefined' && !$('#show-notes')[0].checked) {
$('#comment-list').children('.inline-comment').hide();
diff --git a/src/main/webapp/assets/common/css/gitbucket.css b/src/main/webapp/assets/common/css/gitbucket.css
index 6672acf..63e2901 100644
--- a/src/main/webapp/assets/common/css/gitbucket.css
+++ b/src/main/webapp/assets/common/css/gitbucket.css
@@ -1003,6 +1003,12 @@
background-color: #fff;
}
+.not-diff > .comment-box-container {
+ white-space: initial;
+ line-height: initial;
+ padding: 10px;
+}
+
/****************************************************************************/
/* Repository Settings */
/****************************************************************************/
diff --git a/src/main/webapp/assets/vendors/jsdifflib/diffview.js b/src/main/webapp/assets/vendors/jsdifflib/diffview.js
index ea80600..b9fd2cc 100644
--- a/src/main/webapp/assets/vendors/jsdifflib/diffview.js
+++ b/src/main/webapp/assets/vendors/jsdifflib/diffview.js
@@ -116,9 +116,9 @@
* be returned. Otherwise, tidx is returned, and two empty cells are added
* to the given row.
*/
- function addCells (row, tidx, tend, textLines, change) {
+ function addCells (row, tidx, tend, textLines, change, thclass) {
if (tidx < tend) {
- row.appendChild(telt("th", (tidx + 1).toString()));
+ row.appendChild(addButton(ctelt("th", thclass, (tidx + 1).toString())));
row.appendChild(ctelt("td", change, textLines[tidx].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0")));
return tidx + 1;
} else {
@@ -188,8 +188,8 @@
if (b < be) changeBase = "delete";
if (n < ne) changeNew = "insert";
}
- b = addCells(node, b, be, baseTextLines, changeBase);
- n = addCells(node, n, ne, newTextLines, changeNew);
+ b = addCells(node, b, be, baseTextLines, changeBase, "oldline");
+ n = addCells(node, n, ne, newTextLines, changeNew, "newline");
}
}