<commit_before>﻿window.cls || (window.cls = {});

cls.ScriptSelect = function(id, class_name)
{

  var _selected_value = "";
  var _selected_script_id = 0;
  var _stopped_script_id = "";

  this.getSelectedOptionTooltipText = function()
  {
    _selected_script_id = runtimes.getSelectedScript();
    var script = _selected_script_id && runtimes.getScript(_selected_script_id);
    return script && script.script_type == "linked" && script.uri || null;
  }

  this.getSelectedOptionText = function()
  {
    _selected_script_id = runtimes.getSelectedScript();
    if (_selected_script_id)
    {
      var script = runtimes.getScript(_selected_script_id);
      if (script)
      {
        var script_type = script.script_type.capitalize(true);
        return script.uri
             ? script.filename
             : script_type + " – " + (script.script_data.replace(/\s+/g, " ").slice(0, 300) ||
               ui_strings.S_TEXT_ECMA_SCRIPT_SCRIPT_ID + ': ' + script.script_id);
      }
      else if(_selected_script_id == -1)
      {
        return " ";
      }
      else
      {
        opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
          'missing script in getSelectedOptionText in cls.ScriptSelect');
      }
    }
    else if(runtimes.getSelectedRuntimeId() &&
            runtimes.isReloadedWindow(runtimes.getActiveWindowId()))
    {
      return ui_strings.S_INFO_RUNTIME_HAS_NO_SCRIPTS;
    }
    return '';
  }

  this.getSelectedOptionValue = function()
  {

  }

  this.templateOptionList = function(select_obj)
  {
    this._runtimes = runtimes.get_dom_runtimes(true);
    this._selected_script = runtimes.getSelectedScript();
    return templates.script_dropdown(this._id,
                                     this._runtimes,
                                     _stopped_script_id,
                                     this._selected_script);
  };

  this.onshowoptionlist = function(container)
  {
    var input = container.querySelector("input");
    if (input)
    {
      this._input = input;
      this._clear_button = container.querySelector(".js-dd-clear-filter");
      this._container = container;
      this._script_list = container.querySelector(".js-dd-script-list");
      this._filter.setContainer(container);
      this._filter.setFormInput(input);
      input.focus();
      this._get_option_ele_list();
      this._update_clear_button_state();
    }
  };

  this.onhideoptionlist = function()
  {
    this._filter.cleanup();
    this._filter.set_search_term("");
    this._input = null;
    this._clear_button = null;
    this._container = null;
    this._option_eles = null;
    this._option_box = null;
    this._option_ele_cursor = 0;
  }

  this.checkChange = function(target_ele)
  {
    var script_id_str = target_ele.get_attr('parent-node-chain', 'script-id');
    var script_id = script_id_str && parseInt(script_id_str);
    if (script_id)
    {
      // TODO is this needed?
      if (script_id != _selected_script_id)
      {
        runtimes.setSelectedScript(script_id);
        topCell.showView(views.js_source.id);
        _selected_script_id = script_id;
      }
      _selected_value = target_ele.textContent;
      return true;
    }
    return false;
  }

  // this.updateElement

  var onThreadStopped = function(msg)
  {
    _stopped_script_id = msg.stop_at.script_id;
  }

  var onThreadContinue = function(msg)
  {
    _stopped_script_id = "";
  }

  var onApplicationSetup = function()
  {
    eventHandlers.change['set-tab-size']({target: {value:  settings.js_source.get('tab-size')}});
  }

  this._onfilterinput = function(event, target)
  {
    this._update_clear_button_state();
    this._filter.searchDelayed(target.value);
  };

  this._update_clear_button_state = function()
  {
    if (this._input && this._clear_button)
    {
      if (this._input.value && !this._is_clear_button_visible)
      {
        this._is_clear_button_visible = true; 
        this._clear_button.addClass("js-dd-visible");
      }
      else if (!this._input.value && this._is_clear_button_visible)
      {
        this._is_clear_button_visible = false; 
        this._clear_button.removeClass("js-dd-visible");
      }
    }
  };

  this._onshortcut = function(action_id, event, target)
  {
    switch (action_id)
    {
      case "highlight-next-match":
      case "highlight-previous-match":
        var target = this._option_eles[this._option_ele_cursor];
        if (target)
        {
          if (!this._setting)
            this._init_match_history();

          if (this._input && !this._match_history.contains(this._input.value))
          {
            this._match_history.push(this._input.value);
            while (this._match_history.length > 10)
              this._match_history.shift();

            if (this._setting)
              this._setting.set("js-dd-match-history", this._match_history);
          }          
          target.dispatchMouseEvent("mouseup");
        }
        return false;

      case "up":
        if (this._option_eles.length > 1)
        {
          var index = this._option_ele_cursor - 1;
          if (index < 0)
            index = this._option_eles.length - 1;

          this._move_highlight(index, true);
        }<commit_msg>Possible fix for DFL-2922, Filter history sometimes stops working properly.<commit_after>﻿window.cls || (window.cls = {});

cls.ScriptSelect = function(id, class_name)
{

  var _selected_value = "";
  var _selected_script_id = 0;
  var _stopped_script_id = "";

  this.getSelectedOptionTooltipText = function()
  {
    _selected_script_id = runtimes.getSelectedScript();
    var script = _selected_script_id && runtimes.getScript(_selected_script_id);
    return script && script.script_type == "linked" && script.uri || null;
  }

  this.getSelectedOptionText = function()
  {
    _selected_script_id = runtimes.getSelectedScript();
    if (_selected_script_id)
    {
      var script = runtimes.getScript(_selected_script_id);
      if (script)
      {
        var script_type = script.script_type.capitalize(true);
        return script.uri
             ? script.filename
             : script_type + " – " + (script.script_data.replace(/\s+/g, " ").slice(0, 300) ||
               ui_strings.S_TEXT_ECMA_SCRIPT_SCRIPT_ID + ': ' + script.script_id);
      }
      else if(_selected_script_id == -1)
      {
        return " ";
      }
      else
      {
        opera.postError(ui_strings.S_DRAGONFLY_INFO_MESSAGE +
          'missing script in getSelectedOptionText in cls.ScriptSelect');
      }
    }
    else if(runtimes.getSelectedRuntimeId() &&
            runtimes.isReloadedWindow(runtimes.getActiveWindowId()))
    {
      return ui_strings.S_INFO_RUNTIME_HAS_NO_SCRIPTS;
    }
    return '';
  }

  this.getSelectedOptionValue = function()
  {

  }

  this.templateOptionList = function(select_obj)
  {
    this._runtimes = runtimes.get_dom_runtimes(true);
    this._selected_script = runtimes.getSelectedScript();
    return templates.script_dropdown(this._id,
                                     this._runtimes,
                                     _stopped_script_id,
                                     this._selected_script);
  };

  this.onshowoptionlist = function(container)
  {
    var input = container.querySelector("input");
    if (input)
    {
      this._input = input;
      this._clear_button = container.querySelector(".js-dd-clear-filter");
      this._container = container;
      this._script_list = container.querySelector(".js-dd-script-list");
      this._filter.setContainer(container);
      this._filter.setFormInput(input);
      input.focus();
      this._get_option_ele_list();
      this._update_clear_button_state();
    }
  };

  this.onhideoptionlist = function()
  {
    this._filter.cleanup();
    this._filter.set_search_term("");
    this._input = null;
    this._clear_button = null;
    this._container = null;
    this._option_eles = null;
    this._option_box = null;
    this._option_ele_cursor = 0;
  }

  this.checkChange = function(target_ele)
  {
    var script_id_str = target_ele.get_attr('parent-node-chain', 'script-id');
    var script_id = script_id_str && parseInt(script_id_str);
    if (script_id)
    {
      // TODO is this needed?
      if (script_id != _selected_script_id)
      {
        runtimes.setSelectedScript(script_id);
        topCell.showView(views.js_source.id);
        _selected_script_id = script_id;
      }
      _selected_value = target_ele.textContent;
      return true;
    }
    return false;
  }

  // this.updateElement

  var onThreadStopped = function(msg)
  {
    _stopped_script_id = msg.stop_at.script_id;
  }

  var onThreadContinue = function(msg)
  {
    _stopped_script_id = "";
  }

  var onApplicationSetup = function()
  {
    eventHandlers.change['set-tab-size']({target: {value:  settings.js_source.get('tab-size')}});
  }

  this._onfilterinput = function(event, target)
  {
    this._update_clear_button_state();
    this._filter.searchDelayed(target.value);
  };

  this._update_clear_button_state = function()
  {
    if (this._input && this._clear_button)
    {
      if (this._input.value && !this._is_clear_button_visible)
      {
        this._is_clear_button_visible = true; 
        this._clear_button.addClass("js-dd-visible");
      }
      else if (!this._input.value && this._is_clear_button_visible)
      {
        this._is_clear_button_visible = false; 
        this._clear_button.removeClass("js-dd-visible");
      }
    }
  };

  this._onshortcut = function(action_id, event, target)
  {
    switch (action_id)
    {
      case "highlight-next-match":
      case "highlight-previous-match":
        var target = this._option_eles[this._option_ele_cursor];
        if (target)
        {
          if (!this._setting)
            this._init_match_history();

          if (this._input && this._input.value &&
              !this._match_history.contains(this._input.value))
          {
            this._match_history.push(this._input.value);
            while (this._match_history.length > 10)
              this._match_history.shift();

            if (this._setting)
              this._setting.set("js-dd-match-history", this._match_history);
          }          
          target.dispatchMouseEvent("mouseup");
        }
        return false;

      case "up":
        if (this._option_eles.length > 1)
        {
          var index = this._option_ele_cursor - 1;
          if (index < 0)
            index = this._option_eles.length - 1;

          this._move_highlight(index, true);
        }
{'fraction_non_alphanumeric': 0.11578150146738615, 'fraction_numerical': 0.0028401022436807723, 'mean_word_length': 2.425421530479896, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3083706', 'n_tokens_mistral': 3347, 'n_tokens_neox': 3282, 'n_words': 480}