<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -25,18 +25,18 @@ class AckInProject::Search
 
   def section_start(file)
     self.current_file = file
-    reset_stripe
-    puts %Q|&lt;table class=&quot;file&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot;&gt;|
+    reset_stripe()
+    puts %Q|&lt;table id=&quot;file#{files_matched}&quot; class=&quot;file&quot; width=&quot;100%&quot; cellspacing=&quot;0&quot;&gt;|
     puts %Q|&lt;thead class=&quot;filename&quot;&gt;&lt;tr&gt;&lt;th colspan=&quot;2&quot;&gt;#{current_file}&lt;script&gt;f();&lt;/script&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;|
     puts %Q|&lt;tbody class=&quot;matches&quot;&gt;|
-    file_matched()
   end
   
   def section_end
     if current_file
-      puts %Q|&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;|
       puts %Q|&lt;/tbody&gt;|
       puts %Q|&lt;/table&gt;|
+      puts %Q|&lt;script type=&quot;text/javascript&quot;&gt;searchResultAdded('file#{files_matched}');&lt;/script&gt;|
+      file_matched()
     end
     self.current_file = nil
   end
@@ -56,7 +56,7 @@ class AckInProject::Search
   end
   
   def context_break()
-    reset_stripe
+    reset_stripe()
     puts %Q|&lt;tr class=&quot;context break&quot;&gt;&lt;td&gt;...&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;|
   end
   
@@ -121,7 +121,7 @@ class AckInProject::Search
         when /^(\d+)-(.*)$/
           context_line($1, $2)
         when /^--$/
-          context_break
+          context_break()
         end
         $stdout.flush
       end</diff>
      <filename>Support/lib/search.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,8 +25,8 @@ class AckInProject::SearchResults
     puts &lt;&lt;-HTML
       &lt;h2&gt;Searching for &#8220;#{ h search_string }&#8221; in #{ searched_in }#{note}&lt;/h2&gt;
       &lt;div id=&quot;counters&quot;&gt;&lt;span id=&quot;linecount&quot;&gt;0 lines&lt;/span&gt; matched in &lt;span id=&quot;filecount&quot;&gt;0 files&lt;/span&gt;&lt;/div&gt;
-      &lt;script type=&quot;text/javascript&quot;&gt;searchStarted();&lt;/script&gt;
       &lt;div id=&quot;fold&quot; style=&quot;display:none&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;fold-toggle&quot; /&gt;&lt;span id=&quot;fold-lbl&quot;&gt;Fold Results&lt;/span&gt;&lt;/div&gt;
+      &lt;script type=&quot;text/javascript&quot;&gt;searchStarted();&lt;/script&gt;
     HTML
 
     AckInProject::Search.new(plist).search</diff>
      <filename>Support/lib/search_results.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 var foundFiles = 0;
 var foundLines = 0;
+var folds;
 
 function $(el) {
   return document.getElementById(el);
@@ -17,73 +18,76 @@ function l() {
 
 function searchStarted() {
   $('teaser').style.display = 'none';
+  folds = new FoldSupport();
+}
+
+function searchResultAdded(id) {
+  folds.setupFoldingIn($(id));
 }
 
 function searchCompleted() {
   $('teaser').style.display = 'block';
-  new FoldSupport();
-  // $('fold').style.display = 'block';
-  // $('fold-toggle').addEventListener('change', function() {
-  //   $('fold-lbl').innerHTML = &quot;Unfold results&quot;;
-  // }, false);
+  folds.searchComplete();
 }
 
 function FoldSupport() {
   this.container = $('fold');
   this.checkbox  = $('fold-toggle');
   this.label     = $('fold-lbl');
-  this.results   = document.querySelectorAll('.file');
-  console.log(this.results.length); 
-  this.toggle();
-  this.setupObservers();
 }
 
 FoldSupport.prototype = {
+  searchComplete: function() {
+    this.results = document.querySelectorAll('.file');
+    this.toggle();
+    this.setupObservers();
+  },
+  
   toggle: function() {
-    if(this.container.style.display == 'none')
+    if(this.container.style.display == 'none') {
       this.container.style.display = 'block';
-    else
+    } else {
       this.container.style.display = 'none';
+    }
+  },
+  
+  foldAll: function(fold) {
+    var display = 'none';
+    if(fold) { display = 'block'; }
+    for (var i=0; i &lt; this.results.length; i++) {
+      var file = this.results[i];
+      var matches = file.getElementsByTagName('tbody')[0];
+      matches.style.display = display;
+    };
   },
   
   setupObservers: function() {
     this.setupMainFolding();
-    this.setupTableFolding();
   },
   
-  
   setupMainFolding: function() {
     var self = this;
     this.checkbox.addEventListener('change', function() {
-      var lbl = self.label.innerHTML, display;
+      var lbl = self.label.innerHTML;
       if(lbl.indexOf('Unfold') == -1) {
-        display = 'none';
         self.label.innerHTML = 'Unfold Results';
       } else {
-        display = 'block';
         self.label.innerHTML = 'Fold results';
       }
-    
-      for (var i=0; i &lt; self.results.length; i++) {
-        var file = self.results[i];
-        var matches = file.getElementsByTagName('tbody')[0];
-        matches.style.display = display;
-      };
+      
+      self.foldAll(lbl.indexOf('Unfold') != -1);
     }, false);
   },
   
-  setupTableFolding: function() {
+  setupFoldingIn: function(node) {
     var self = this;
-    for (var i=0; i &lt; this.results.length; i++) {
-      var file = this.results[i];
-      var hdr = file.getElementsByTagName('thead')[0];
-      hdr.addEventListener('click', function() {
-        var node = this.parentNode; 
-        if(node.tagName.toLowerCase() == 'table') {
-          self.toggleMatchesIn(node);
-        }
-      }, false);
-    }
+    var hdr = node.getElementsByTagName('thead')[0];
+    hdr.addEventListener('click', function() {
+      var parent = this.parentNode;
+      if(parent.tagName.toLowerCase() == 'table') {
+        self.toggleMatchesIn(parent);
+      }
+    }, false);
   },
   
   toggleMatchesIn: function(table) {
@@ -93,4 +97,4 @@ FoldSupport.prototype = {
     else
       matches.style.display = 'none';
   }
-}
\ No newline at end of file
+}</diff>
      <filename>Support/search.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c5a19c848c8dd46d6cc7a1270f4d8493dce1fc8a</id>
    </parent>
  </parents>
  <author>
    <name>David Lynch</name>
    <email>kemayo@gmail.com</email>
  </author>
  <url>http://github.com/adinardi/ack-tmbundle/commit/152ebde12aa0557abc9529f728310ff48bb51c69</url>
  <id>152ebde12aa0557abc9529f728310ff48bb51c69</id>
  <committed-date>2009-11-05T04:54:22-08:00</committed-date>
  <authored-date>2009-03-10T12:12:51-07:00</authored-date>
  <message>Rework folding so it works before the search ends

(I work on a very big project. A search for a common word can
take a long time, and have some very long individual results.)</message>
  <tree>c8e161b844684b7bed045eb8d935d272d5ea33eb</tree>
  <committer>
    <name>Angelo DiNardi</name>
    <email>adinardi@fragtop.local</email>
  </committer>
</commit>
