]> source.dussan.org Git - gitblit.git/commitdiff
Adjust blob view layout to improve line links (issue 130)
authorJames Moger <james.moger@gitblit.com>
Mon, 17 Sep 2012 13:26:32 +0000 (09:26 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 17 Sep 2012 13:26:32 +0000 (09:26 -0400)
http://nicolasgallagher.com/jump-links-and-viewport-positioning

resources/gitblit.css
src/com/gitblit/wicket/pages/BlobPage.java

index 861fc41170922631932ce1f71e8424722e123684..bbd3c0c260758f69828292dba8e3da135d871788 100644 (file)
@@ -178,6 +178,19 @@ pre.prettyprint ol {
     vertical-align:top;\r
 }\r
 \r
+/* CSS trick to workaround #link topOfWindow offset problem */\r
+#lines .line {\r
+    border-top: 160px solid transparent;\r
+    margin-top: -160px;\r
+    -webkit-background-clip: padding-box;\r
+    -moz-background-clip: padding;\r
+    background-clip: padding-box;\r
+}\r
+\r
+#lines span:target {\r
+       background-color: #ffffbf;\r
+}\r
+\r
 #nums pre {\r
     white-space: pre;\r
 }\r
index f1d802d4ee6b3a8fd66819dc5cef90a79d353365..ebe539f27d908d043ea635dd1cec005090b5b9cf 100644 (file)
@@ -149,7 +149,7 @@ public class BlobPage extends RepositoryPage {
                sb.append("<!-- start nums column -->");\r
                sb.append("<td id=\"nums\">");\r
                sb.append("<pre>");\r
-               String numPattern = "<a id=\"L{0}\" href=\"#L{0}\">{0}</a>\n";\r
+               String numPattern = "<a href=\"#L{0}\">{0}</a>\n";\r
                for (int i = 0; i < lines.length; i++) {\r
                        sb.append(MessageFormat.format(numPattern, "" + (i + 1)));\r
                }\r
@@ -165,7 +165,12 @@ public class BlobPage extends RepositoryPage {
                } else {\r
                        sb.append("<pre class=\"plainprint\">");\r
                }\r
-               sb.append(StringUtils.escapeForHtml(source, true));\r
+               lines = StringUtils.escapeForHtml(source, true).split("\n");\r
+               for (int i = 0; i < lines.length; i++) {\r
+                       sb.append(MessageFormat.format("<span id=\"L{0}\" class=\"line\">", "" + (i + 1)));\r
+                       sb.append(lines[i]);\r
+                       sb.append("</span>");\r
+               }\r
                sb.append("</pre>");\r
                sb.append("</div>");\r
                sb.append("</td>");\r