Skip to content
Permalink
Browse files

refs #7055, use css to show the line number to avoid line number sele…

…ction during copy & paste
  • Loading branch information...
walty8 committed Jun 20, 2016
1 parent 2b63ace commit 4ea3e0caa81009e7139393a871833a093a458388
Showing with 22 additions and 19 deletions.
  1. +3 −0 trac/htdocs/css/diff.css
  2. +19 −19 trac/templates/diff_div.html
@@ -203,3 +203,6 @@ pre.diff .add { background: #dfd; }

/* Styles for the diff page */
.trac-autocomplete-dir { font-weight: bold }

/* Set up line numbers */
th[data-line-prefix]:before { content: attr(data-line-prefix); }
@@ -142,11 +142,11 @@ <h2 id="${'file%s' % idx if not no_id else None}" py:choose="">
clines = block.changed.lines">
<py:choose test="diff.style">
<py:when test="'sidebyside'">
<th>$from_n</th><td class="l"><span>$line</span></td>
<th>$to_n</th><td class="r"><span>${clines[idx] if idx &lt; len(clines) else None}</span></td>
<th data-line-prefix="$from_n"></th><td class="l"><span>$line</span></td>
<th data-line-prefix="$to_n"></th><td class="r"><span>${clines[idx] if idx &lt; len(clines) else None}</span></td>
</py:when>
<py:when test="'inline'">
<th>$from_n</th><th>$to_n</th><td class="l"><span>$line</span></td>
<th data-line-prefix="$from_n"></th><th data-line-prefix="$to_n"></th><td class="l"><span>$line</span></td>
</py:when>
</py:choose>
</py:with>
@@ -159,11 +159,11 @@ <h2 id="${'file%s' % idx if not no_id else None}" py:choose="">
<py:with vars="to_n = block.changed.offset+idx+1">
<py:choose test="diff.style">
<py:when test="'sidebyside'">
<th>&nbsp;</th><td class="l"></td>
<th>$to_n</th><td class="r"><ins>$line</ins></td>
<th data-line-prefix="&nbsp;"></th><td class="l"></td>
<th data-line-prefix="$to_n"></th><td class="r"><ins>$line</ins></td>
</py:when>
<py:when test="'inline'">
<th>&nbsp;</th><th>$to_n</th><td class="r"><ins>$line</ins></td>
<th data-line-prefix="&nbsp;"></th><th data-line-prefix="$to_n"></th><td class="r"><ins>$line</ins></td>
</py:when>
</py:choose>
</py:with>
@@ -176,11 +176,11 @@ <h2 id="${'file%s' % idx if not no_id else None}" py:choose="">
<py:with vars="from_n = block.base.offset+idx+1">
<py:choose test="diff.style">
<py:when test="'sidebyside'">
<th>$from_n</th><td class="l"><del>$line</del></td>
<th>&nbsp;</th><td class="r"></td>
<th data-line-prefix="$from_n"></th><td class="l"><del>$line</del></td>
<th data-line-prefix="&nbsp;"></th><td class="r"></td>
</py:when>
<py:when test="'inline'">
<th>$from_n</th><th>&nbsp;</th><td class="l"><del>$line</del></td>
<th data-line-prefix="$from_n"></th><th data-line-prefix="&nbsp;"></th><td class="l"><del>$line</del></td>
</py:when>
</py:choose>
</py:with>
@@ -193,21 +193,21 @@ <h2 id="${'file%s' % idx if not no_id else None}" py:choose="">
<py:choose>
<py:when test="len(block.base.lines) &gt;= len(block.changed.lines)">
<tr py:for="idx, line in enumerate(block.base.lines)">
<th>${block.base.offset+idx+1}</th>
<th data-line-prefix="${block.base.offset+idx+1}"></th>
<td class="l"><span>$line</span></td>
<py:with vars="within_change = idx &lt; len(block.changed.lines)">
<th>${block.changed.offset + idx + 1 if within_change else '&nbsp;'}</th>
<th data-line-prefix="${block.changed.offset + idx + 1 if within_change else '&nbsp;'}"></th>
<td class="r"><span py:if="within_change">${block.changed.lines[idx]}</span></td>
</py:with>
</tr>
</py:when>
<py:otherwise> <!--! there are more changed lines than original lines -->
<tr py:for="idx, line in enumerate(block.changed.lines)">
<py:with vars="within_change = idx &lt; len(block.base.lines)">
<th>${block.base.offset + idx + 1 if within_change else '&nbsp;'}</th>
<th data-line-prefix="${block.base.offset + idx + 1 if within_change else '&nbsp;'}"></th>
<td class="l"><span py:if="within_change">${block.base.lines[idx]}</span></td>
</py:with>
<th>${block.changed.offset + idx + 1}</th>
<th data-line-prefix="${block.changed.offset + idx + 1}"></th>
<td class="r"><span>$line</span></td>
</tr>
</py:otherwise>
@@ -217,12 +217,12 @@ <h2 id="${'file%s' % idx if not no_id else None}" py:choose="">
<!--! First show the "old" lines -->
<tr py:for="idx, line in enumerate(block.base.lines)"
class="${'first' if idx == 0 else None}">
<th>${block.base.offset + idx + 1}</th><th>&nbsp;</th><td class="l"><span>$line</span></td>
<th data-line-prefix="${block.base.offset + idx + 1}"></th><th data-line-prefix="&nbsp;"></th><td class="l"><span>$line</span></td>
</tr>
<!--! Then show the "new" lines -->
<tr py:for="idx, line in enumerate(block.changed.lines)"
class="${'last' if idx + 1 == len(block.changed.lines) else None}">
<th>&nbsp;</th><th>${block.changed.offset + idx + 1}</th><td class="r"><span>$line</span></td>
<th data-line-prefix="&nbsp;"></th><th data-line-prefix="${block.changed.offset + idx + 1}"></th><td class="r"><span>$line</span></td>
</tr>
</py:when>
</py:choose>
@@ -235,12 +235,12 @@ <h2 id="${'file%s' % idx if not no_id else None}" py:choose="">
py:with="fromline = item.diffs[idx+1][0].base.offset+1;
toline = item.diffs[idx+1][0].changed.offset+1">
<tr py:when="'sidebyside'">
<th><a href="$old.href#L$fromline">&hellip;</a></th><td>&nbsp;</td>
<th><a href="$new.href#L$toline">&hellip;</a></th><td>&nbsp;</td>
<th data-line-prefix="&hellip;"><a href="$old.href#L$fromline"></a></th><td>&nbsp;</td>
<th data-line-prefix="&hellip;"><a href="$new.href#L$toline"></a></th><td>&nbsp;</td>
</tr>
<tr py:when="'inline'">
<th><a href="$old.href#L$fromline">&hellip;</a></th>
<th><a href="$new.href#L$toline">&hellip;</a></th>
<th data-line-prefix="&hellip;"><a href="$old.href#L$fromline"></a></th>
<th data-line-prefix="&hellip;"><a href="$new.href#L$toline"></a></th>
<td><em py:if="'diffs_title' in item">${item.diffs_title[idx+1]}</em>&nbsp;</td>
</tr>
</tbody>

0 comments on commit 4ea3e0c

Please sign in to comment.
You can’t perform that action at this time.