export default (function () {
  function LogFolder(element) {
    this.element = element;
    if (this.element) {
      const handleClick = (event) => {
        let folder = this.getFolderFromLine(event.target);
        this.toggle(folder);
        event.preventDefault();
      };

      this.element.addEventListener('click', handleClick);
    }
  }

  LogFolder.prototype.fold = function (line) {
    let folder;
    folder = this.getFolderFromLine(line);
    if (folder.classList && folder.classList.contains('open')) {
      return this.toggle(folder);
    }
  };

  LogFolder.prototype.unfold = function (line) {
    let folder;
    folder = this.getFolderFromLine(line);
    if (folder.classList && !folder.classList.contains('open')) {
      return this.toggle(folder);
    }
  };

  LogFolder.prototype.toggle = function (folder) {
    return folder.classList && folder.classList.toggle('open');
  };

  LogFolder.prototype.getFolderFromLine = function (line) {
    let currentLine = line;
    while (currentLine.parentNode) {
      currentLine = currentLine.parentNode;
      if (currentLine.classList && currentLine.classList.contains('fold')) {
        break;
      }
    }
    return currentLine;
  };

  return LogFolder;
}());

@@ -393,39 +393,29 @@
 line) %7B%0A    
-let folder;%0A   
+const
  folder = th
@@ -448,32 +448,42 @@
 ;%0A    if (folder
+ && folder
 .classList && fo
@@ -620,23 +620,13 @@
     
-let folder;%0A   
+const
  fol
@@ -671,24 +671,34 @@
   if (folder
+ && folder
 .classList &
@@ -844,16 +844,26 @@
   return
+ folder &&
  folder.
@@ -986,27 +986,73 @@
 let 
-currentLine = line;
+firstFoldLine, currentElem = line, parentElem = line.parentNode;%0A
 %0A   
@@ -1063,154 +1063,340 @@
 le (
-cur
+pa
 rent
-Line.parentNode) %7B%0A      currentLine = currentLine.parentNode;%0A      if (currentLine.classList && currentLine.classList.contains('fold')) %7B
+Elem) %7B%0A      if (!parentElem.classList %7C%7C parentElem.classList.contains('log-body-content')) %7B%0A        break;%0A      %7D%0A%0A      if (parentElem.classList.contains('fold')) %7B%0A        const %7B children %7D = parentElem;%0A        if (children.length %3E= 2 && children%5B1%5D === currentElem) %7B%0A          firstFoldLine = parentElem;%0A        %7D
 %0A   
@@ -1419,32 +1419,122 @@
   %7D%0A
+%0A  
     
-%7D%0A    return current
+currentElem = currentElem.parentNode;%0A      parentElem = parentElem.parentNode;%0A    %7D%0A%0A    return firstFold
 Line

Fix issue where clicking on fold child closes fold (#2273)