<commit_before>function SmartBehavior(oframp) {
  this.__init(oframp);
}

SmartBehavior.prototype = {
  name: "Smart",

  __needle: undefined,
  __fragments: undefined,
  __currentFragment: undefined,

  __init: function(oframp) {
    this.oframp = oframp;
    var _this = this;
    $ext.dom.addEventListener(oframp.container, 'moleculedisplayed',
        function() {
          var ffb = document.getElementById("find_fragments");
          var pe = ffb.parentElement;
          if(ffb) {
            $ext.dom.remove(ffb);
          } else {
            var fcd = document.getElementById("fragment_controls");
            if(fcd) {
              $ext.dom.clear(fcd);
            }
          }
          ffb = document.createElement("button");
          ffb.id = "find_fragments";
          ffb.className = "border_box";
          ffb.appendChild(document.createTextNode("Start parameterising"));
          pe.appendChild(ffb);
          _this.__ffb = ffb;

          $ext.dom.onMouseClick(ffb, function() {
            _this.__selectAtom();
          }, $ext.mouse.LEFT);
        });

    $ext.dom.addEventListener(oframp.container, 'historychanged', function() {
      if(!_this.__ffb || !_this.__afb || !_this.__rfb || !_this.__pfb) {
        return;
      }

      if(_this.oframp.mv.molecule.getUnparameterized().length > 0) {
        if(_this.__needle === undefined) {
          _this.__ffb.style.display = "inline-block";
          _this.__afb.style.display = "none";
          _this.__rfb.style.display = "none";
          _this.__pfb.style.display = "none";
        } else {
          _this.__ffb.style.display = "none";
          _this.__afb.style.display = "inline-block";
          _this.__rfb.style.display = "inline-block";
          _this.__pfb.style.display = "inline-block";
        }
      } else {
        _this.__ffb.style.display = "none";
        _this.__afb.style.display = "none";
        _this.__rfb.style.display = "none";
        _this.__pfb.style.display = "none";
      }
    });
  },

  getJSON: function() {
    return {
      needle: this.__needle,
      fragments: this.__fragments,
      currentFragment: this.__currentFragment
    };
  },

  loadJSON: function(data) {
    this.__needle = data.needle;
    this.__fragments = data.fragments;
    this.__currentFragment = data.currentFragment;

    if(this.__needle !== undefined) {
      this.oframp.mv.molecule.centerOnAtom(this.__needle);
      if(this.__currentFragment !== undefined) {
        this.__showFragment(this.__currentFragment);
      }
    } else {
      this.oframp.mv.molecule.center();
    }
  },

  showSelectionDetails: function(selection) {
    NaiveBehavior.prototype.showSelectionDetails.call(this, selection);
  },

  __selectAtom: function() {
    var unpar = this.oframp.mv.molecule.getUnparameterized();
    if(!unpar) {
      alert("Could not find any more unparameterised atoms.");
      return;
    }
<commit_msg>Atom centering is not necessary when going through history.<commit_after>function SmartBehavior(oframp) {
  this.__init(oframp);
}

SmartBehavior.prototype = {
  name: "Smart",

  __needle: undefined,
  __fragments: undefined,
  __currentFragment: undefined,

  __init: function(oframp) {
    this.oframp = oframp;
    var _this = this;
    $ext.dom.addEventListener(oframp.container, 'moleculedisplayed',
        function() {
          var ffb = document.getElementById("find_fragments");
          var pe = ffb.parentElement;
          if(ffb) {
            $ext.dom.remove(ffb);
          } else {
            var fcd = document.getElementById("fragment_controls");
            if(fcd) {
              $ext.dom.clear(fcd);
            }
          }
          ffb = document.createElement("button");
          ffb.id = "find_fragments";
          ffb.className = "border_box";
          ffb.appendChild(document.createTextNode("Start parameterising"));
          pe.appendChild(ffb);
          _this.__ffb = ffb;

          $ext.dom.onMouseClick(ffb, function() {
            _this.__selectAtom();
          }, $ext.mouse.LEFT);
        });

    $ext.dom.addEventListener(oframp.container, 'historychanged', function() {
      if(!_this.__ffb || !_this.__afb || !_this.__rfb || !_this.__pfb) {
        return;
      }

      if(_this.oframp.mv.molecule.getUnparameterized().length > 0) {
        if(_this.__needle === undefined) {
          _this.__ffb.style.display = "inline-block";
          _this.__afb.style.display = "none";
          _this.__rfb.style.display = "none";
          _this.__pfb.style.display = "none";
        } else {
          _this.__ffb.style.display = "none";
          _this.__afb.style.display = "inline-block";
          _this.__rfb.style.display = "inline-block";
          _this.__pfb.style.display = "inline-block";
        }
      } else {
        _this.__ffb.style.display = "none";
        _this.__afb.style.display = "none";
        _this.__rfb.style.display = "none";
        _this.__pfb.style.display = "none";
      }
    });
  },

  getJSON: function() {
    return {
      needle: this.__needle,
      fragments: this.__fragments,
      currentFragment: this.__currentFragment
    };
  },

  loadJSON: function(data) {
    this.__needle = data.needle;
    this.__fragments = data.fragments;
    this.__currentFragment = data.currentFragment;

    if(this.__needle !== undefined) {
      if(this.__currentFragment !== undefined) {
        this.__showFragment(this.__currentFragment);
      }
    } else {
      this.oframp.mv.molecule.center();
    }
    this.oframp.redraw();
  },

  showSelectionDetails: function(selection) {
    NaiveBehavior.prototype.showSelectionDetails.call(this, selection);
  },

  __selectAtom: function() {
    var unpar = this.oframp.mv.molecule.getUnparameterized();
    if(!unpar) {
      alert("Could not find any more unparameterised atoms.");
      return;
    }

{'fraction_non_alphanumeric': 0.13499232998125107, 'fraction_numerical': 0.0003408897221748764, 'mean_word_length': 2.324645892351275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5892949', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1826, 'n_words': 272}