1. scope
  2. scope.bitbucket.org

Commits

Christian Krebs  committed a560275

Testing 'Go to line number'.

  • Participants
  • Parent commits cabc89f
  • Branches default

Comments (0)

Files changed (2)

File tests/js-highlight-performance/index.html

View file
 <link rel="stylesheet" href="../../resources/ui-style/syntax-highlight.css">
 <link rel="alternate stylesheet" title="t1" href="./dragonfly.css">
 <style>
-body
+html, body
 {
   margin: 0;
   padding: 0;
+  height: 100%;
 }
 form
 {
 }
 .source
 {
-  position: relative;
+  position: absolute;
+  top: 220px;
+  bottom: 0px;
+  width: 100%;
   white-space: pre;
   font-family: monospace;
   font-size: 12px;
   line-height: 15px;
   border-top: 1px solid hsl(0, 0%, 70%);
+  overflow: auto;
 }
 .js-source 
 {
                             <option>10</option>
                             <option>50</option>
                           </select></label>
+       <label><input type="text">
+              <input type="button" 
+                     value="scroll to" 
+                     onclick="go_to_line(Number(this.previousElementSibling.value))" 
+                     ></label>
     <div></div>
   </form>
   <div id="controls">loading 1.5 MB js source file ...</div>

File tests/js-highlight-performance/testhighlight.js

View file
   }, 0);
 };
 
+var go_to_line = function(line)
+{
+  var target = document.getElementsByClassName('js-source')[0];
+  if (target)
+  {
+    target = target.childNodes;
+    const TEXT = document.TEXT_NODE;
+    var count = 0;
+    var pos = 0;
+    var span = document.createElement('span');
+    span.textContent = ' ';
+    for (var i = 0, child; child = target[i]; i++)
+    {
+      if (child.nodeType == TEXT)
+      {
+        pos = -1;
+        while (true)
+        {
+          pos = child.nodeValue.indexOf('\n', pos + 1);
+          if (pos == -1)
+            break;
+          count++;
+          if (count == line)
+          {
+            var target_node = child.splitText(pos);
+            child.parentNode.insertBefore(span, target_node);
+            i = target.length;
+            var top = span.getBoundingClientRect().top;
+            span.textContent = '';
+            var container = document.getElementsByClassName('source')[0];
+            var cont_top = container.getBoundingClientRect().top;
+            container.scrollTop += top - cont_top;
+            //span.scrollIntoView();
+            return;
+          }
+        }
+      }
+    }
+    
+  }
+};
+
 labels["template"] =
 [
   "tokenize and create template",