Bug 700361 - Make viewSource.js assume a pre without an id starts on line 1. r=gavin.sharp.
authorHenri Sivonen <hsivonen@iki.fi>
Wed, 16 Nov 2011 09:38:51 +0200
changeset 81984 b534bab26edf837a8ea65313ad502086febfec11
parent 81983 5135cc4e6a368f6261ebb90eb727dcd38731100d
child 81985 48757a990949b7481723507757c58b1bf7dd0f5e
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs700361
milestone11.0a1
Bug 700361 - Make viewSource.js assume a pre without an id starts on line 1. r=gavin.sharp.
toolkit/components/viewsource/content/viewSource.js
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -462,23 +462,25 @@ function ViewSourceGoToLine()
 function goToLine(line)
 {
   var viewsource = window.content.document.body;
 
   // The source document is made up of a number of pre elements with
   // id attributes in the format <pre id="line123">, meaning that
   // the first line in the pre element is number 123.
   // Do binary search to find the pre element containing the line.
+  // However, in the plain text case, we have only one pre without an
+  // attribute, so assume it begins on line 1.
 
   var pre;
   for (var lbound = 0, ubound = viewsource.childNodes.length; ; ) {
     var middle = (lbound + ubound) >> 1;
     pre = viewsource.childNodes[middle];
 
-    var firstLine = parseInt(pre.id.substring(4));
+    var firstLine = pre.id ? parseInt(pre.id.substring(4)) : 1;
 
     if (lbound == ubound - 1) {
       break;
     }
 
     if (line >= firstLine) {
       lbound = middle;
     } else {
@@ -587,17 +589,19 @@ function findLocation(pre, line, node, o
     for (pre = node;
          pre.nodeName != "PRE";
          pre = pre.parentNode);
   }
 
   // The source document is made up of a number of pre elements with
   // id attributes in the format <pre id="line123">, meaning that
   // the first line in the pre element is number 123.
-  var curLine = parseInt(pre.id.substring(4));
+  // However, in the plain text case, there is only one <pre> without an id,
+  // so assume line 1.
+  var curLine = pre.id ? parseInt(pre.id.substring(4)) : 1;
 
   // Walk through each of the text nodes and count newlines.
   var treewalker = window.content.document
       .createTreeWalker(pre, NodeFilter.SHOW_TEXT, null, false);
 
   // The column number of the first character in the current text node.
   var firstCol = 1;