(refs #549) Selecting lines in diff without line numbers.

This commit is contained in:
Shintaro Murakami
2015-01-10 00:30:28 +09:00
parent 485d502bd3
commit c597238d9c
3 changed files with 33 additions and 21 deletions

View File

@@ -154,15 +154,13 @@ $(function(){
tmp = getInlineContainer('old'); tmp = getInlineContainer('old');
} }
tmp.children('td:first').html($(this).clone().show()); tmp.children('td:first').html($(this).clone().show());
$('table[filename="' + filename + '"]').find('table.diff').find('.oldline').filter(function() { $('table[filename="' + filename + '"]').find('table.diff').find('.oldline[line-number=' + oldline + ']')
return new RegExp('^' + oldline + '[\\+]*$').test($(this).text()); .parent().nextAll(':not(.not-diff):first').before(tmp);
}).parent().nextAll(':not(.not-diff):first').before(tmp);
} else { } else {
var tmp = getInlineContainer('new'); var tmp = getInlineContainer('new');
tmp.children('td:last').html($(this).clone().show()); tmp.children('td:last').html($(this).clone().show());
$('table[filename="' + filename + '"]').find('table.diff').find('.newline').filter(function() { $('table[filename="' + filename + '"]').find('table.diff').find('.newline[line-number=' + newline + ']')
return new RegExp('^' + newline + '\\+$').test($(this).text()); .parent().nextAll(':not(.not-diff):first').before(tmp);
}).parent().nextAll(':not(.not-diff):first').before(tmp);
} }
}); });
$('.toggle-notes').change(function() { $('.toggle-notes').change(function() {
@@ -172,7 +170,7 @@ $(function(){
$(this).closest('table').find('.not-diff').toggle(); $(this).closest('table').find('.not-diff').toggle();
}); });
@if(hasWritePermission) { @if(hasWritePermission) {
$('table.diff th').hover( $('table.diff td').hover(
function() { function() {
$(this).find('b').css('display', 'inline-block'); $(this).find('b').css('display', 'inline-block');
}, },
@@ -180,12 +178,12 @@ $(function(){
$(this).find('b').css('display', 'none'); $(this).find('b').css('display', 'none');
} }
); );
$('table.diff td').hover( $('table.diff th').hover(
function() { function() {
$(this).prev('th').find('b').css('display', 'inline-block'); $(this).closest('tr').find('td').find('b').css('display', 'inline-block');
}, },
function() { function() {
$(this).prev('th').find('b').css('display', 'none'); $(this).closest('tr').find('td').find('b').css('display', 'none');
} }
); );
$('.add-comment').click(function() { $('.add-comment').click(function() {
@@ -198,12 +196,14 @@ $(function(){
if (!$tr.nextAll(':not(.not-diff):first').prev().hasClass('inline-comment-form')) { if (!$tr.nextAll(':not(.not-diff):first').prev().hasClass('inline-comment-form')) {
var commitId = $this.closest('.table-bordered').attr('commitId'), var commitId = $this.closest('.table-bordered').attr('commitId'),
fileName = $this.closest('.table-bordered').attr('fileName'), fileName = $this.closest('.table-bordered').attr('fileName'),
oldLineNumber, newLineNumber = $this.closest('.newline').clone().children().remove().end().text(), oldLineNumber, newLineNumber,
url = '@url(repository)/commit/' + commitId + '/comment/_form?fileName=' + fileName@issueId.map { id => + '&issueId=@id' }; url = '@url(repository)/commit/' + commitId + '/comment/_form?fileName=' + fileName@issueId.map { id => + '&issueId=@id' };
if (viewType == 0) { if (viewType == 0) {
oldLineNumber = $this.closest('.oldline').clone().children().remove().end().text(); oldLineNumber = $this.parent().prev('.oldline').attr('line-number');
newLineNumber = $this.parent().prev('.newline').attr('line-number');
} else { } else {
oldLineNumber = $this.closest('tr').find('.oldline').text(); oldLineNumber = $this.parent().prevAll('.oldline').attr('line-number');
newLineNumber = $this.parent().prevAll('.newline').attr('line-number');
} }
if (!isNaN(oldLineNumber) && oldLineNumber) { if (!isNaN(oldLineNumber) && oldLineNumber) {
url += ('&oldLineNumber=' + oldLineNumber) url += ('&oldLineNumber=' + oldLineNumber)

View File

@@ -975,15 +975,16 @@ table.diff .add-comment {
position: absolute; position: absolute;
background: blue; background: blue;
top: 0; top: 0;
left: -7px;
color: white; color: white;
padding: 2px; padding: 2px 4px;
border: solid 1px blue; border: solid 1px blue;
border-radius: 3px; border-radius: 3px;
z-index: 99; z-index: 99;
} }
table.diff .add-comment:hover { table.diff .add-comment:hover {
padding: 4px; padding: 4px 6px;
top: -1px; top: -1px;
} }
@@ -1009,6 +1010,10 @@ table.diff tbody tr.not-diff:hover td{
padding: 10px; padding: 10px;
} }
.diff .oldline:before, .diff .newline:before {
content: attr(line-number);
}
/****************************************************************************/ /****************************************************************************/
/* Repository Settings */ /* Repository Settings */
/****************************************************************************/ /****************************************************************************/

View File

@@ -84,7 +84,7 @@ diffview = {
b.appendChild(document.createTextNode("+")); b.appendChild(document.createTextNode("+"));
b.style.display = "none"; b.style.display = "none";
b.className = "add-comment"; b.className = "add-comment";
e.appendChild(b); e.insertBefore(b, e.firstChild);
e.style.position = "relative"; e.style.position = "relative";
return e; return e;
} }
@@ -117,9 +117,12 @@ diffview = {
* to the given row. * to the given row.
*/ */
function addCells (row, tidx, tend, textLines, change, thclass) { function addCells (row, tidx, tend, textLines, change, thclass) {
var tmp;
if (tidx < tend) { if (tidx < tend) {
row.appendChild(addButton(ctelt("th", thclass, (tidx + 1).toString()))); tmp = ctelt("th", thclass, "");
row.appendChild(ctelt("td", change, textLines[tidx].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0"))); tmp.setAttribute("line-number", (tidx + 1).toString());
row.appendChild(tmp);
row.appendChild(addButton(ctelt("td", change, textLines[tidx].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0"))));
return tidx + 1; return tidx + 1;
} else { } else {
row.appendChild(document.createElement("th")); row.appendChild(document.createElement("th"));
@@ -129,9 +132,13 @@ diffview = {
} }
function addCellsInline (row, tidx, tidx2, textLines, change) { function addCellsInline (row, tidx, tidx2, textLines, change) {
row.appendChild(ctelt("th", "oldline", tidx == null ? "" : (tidx + 1).toString())); var tmp = ctelt("th", "oldline", "");
row.appendChild(addButton(ctelt("th", "newline", tidx2 == null ? "" : (tidx2 + 1).toString()))); tmp.setAttribute("line-number", tidx == null ? "" : (tidx + 1).toString());
row.appendChild(ctelt("td", change, textLines[tidx != null ? tidx : tidx2].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0"))); row.appendChild(tmp);
tmp = ctelt("th", "newline", "");
tmp.setAttribute("line-number", tidx2 == null ? "" : (tidx2 + 1).toString());
row.appendChild(tmp);
row.appendChild(addButton(ctelt("td", change, textLines[tidx != null ? tidx : tidx2].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0"))));
} }
for (var idx = 0; idx < opcodes.length; idx++) { for (var idx = 0; idx < opcodes.length; idx++) {