<commit_before>var RomoSelectedOptionsList = function(focusElem) {
  this.elem      = undefined;
  this.focusElem = focusElem; // picker/select dropdown elem

  this.items = [];

  this.doInit();
  this._bindElem();
}

RomoSelectedOptionsList.prototype.doInit = function() {
  // override as needed
}

/*
Options are specified as a list of items.  Each 'option' item object
has display text and a value. They are compatible with the option list
dropdown option items.

Example:
[ { 'type': 'option', 'value': 'a', 'displayText': 'A' },
  { 'type': 'option', 'value': 'b', 'displayText': 'B' },
  { 'type': 'option', 'value': 'c', 'displayText': 'C' }
]
*/

RomoSelectedOptionsList.prototype.doSetItems = function(itemsList) {
  this.items = itemsList;
}

RomoSelectedOptionsList.prototype.doClearItems = function() {
  this.items = [];
}

RomoSelectedOptionsList.prototype.doAddItem = function(item) {
  if (!this._getItemValues().includes(item.value)) {
    this.items.push(item);
  }
}

RomoSelectedOptionsList.prototype.doRemoveItem = function(itemValue) {
  var index = this._getItemValues().indexOf(itemValue);
  if (index > -1) {
    this.items.splice(index, 1);
  }
}

RomoSelectedOptionsList.prototype.doRefreshUI = function() {
  var itemValues  = this._getItemValues();
  var uiListElem  = this.elem.find('.romo-selected-options-list-items');
  var uiItemElems = uiListElem.find('.romo-selected-options-list-item');
  var uiValues    = uiItemElems.get().map(function(uiItemNode) {
    return $(uiItemNode).data('romo-selected-options-list-value');
  });
  var rmNodes = uiItemElems.get().filter(function(uiItemNode) {
     return itemValues.indexOf($(uiItemNode).data('romo-selected-options-list-value')) === -1;
   });
  var addItems = this.items.filter(function(item) {
    return uiValues.indexOf(item.value) === -1;
  });
  rmNodes.forEach($.proxy(function(rmNode) {
    $(rmNode).remove();
  }, this));
  addItems.forEach($.proxy(function(addItem) {
    var addElem = this._buildItemElem(addItem);
    uiListElem.append(addElem);

    var listWidth       = parseInt(Romo.getComputedStyle(uiListElem[0], "width"), 10);
    var listLeftPad     = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-left"), 10);
    var listRightPad    = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-right"), 10);
    var itemBorderWidth = 1;
    var itemLeftPad     = parseInt(Romo.getComputedStyle(addElem[0], "padding-left"), 10);
    var itemRightPad    = parseInt(Romo.getComputedStyle(addElem[0], "padding-right"), 10);
    addElem.find('DIV').css('max-width', String(listWidth-listLeftPad-listRightPad-(2*itemBorderWidth)-itemLeftPad-itemRightPad)+'px');
  }, this));

  var focusElemWidth = parseInt(Romo.getComputedStyle(this.focusElem[0], "width"), 10);
  this.elem.css('width', String(focusElemWidth)+'px');

  var maxRows          = undefined;
  var uiListElemHeight = parseInt(Romo.getComputedStyle(uiListElem[0], "height"), 10);
  var firstItemNode    = uiListElem.find('.romo-selected-options-list-item')[0];
  if (firstItemNode !== undefined) {
    var itemHeight       = parseInt(Romo.getComputedStyle(firstItemNode, "height"), 10);
    var itemMarginBottom = parseInt(Romo.getComputedStyle(firstItemNode, "margin-bottom"), 10);
    var itemBorderWidth  = 1;
    var listTopPad       = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-top"), 10);
    var listBottomPad    = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-bottom"), 10);

    var maxRows   = this.focusElem.data('romo-selected-options-list-max-rows') || 0;
    var maxHeight = listTopPad+(itemHeight*maxRows)+(itemMarginBottom*(maxRows-1))+(2*itemBorderWidth*maxRows)+listBottomPad+(itemHeight/2);
  }
  if (maxRows !== undefined && (uiListElemHeight > maxHeight)) {
    this.elem.css({
      'height':     String(maxHeight)+'px',
      'overflow-y': 'auto'
    });
    var itemElems    = uiListElem.find('.romo-selected-options-list-item');
    var lastItemNode = itemElems[itemElems.length-1];
    this._scrollListTopToItem($(lastItemNode));
  } else {
    this.elem.css({
      'height':     String(uiListElemHeight)+'px',
      'overflow-y': undefined
    });
  }
}

/* private */

RomoSelectedOptionsList.prototype._bindElem = function() {
  this.elem = $('<div class="romo-selected-options-list"><div class="romo-selected-options-list-items"></div></div>');

  this.elem.on('click', $.proxy(function(e) {
    if (e !== undefined) {
      e.stopPropagation();<commit_msg>(hotfix) fix bug in calculating handling max height in sel opt list<commit_after>var RomoSelectedOptionsList = function(focusElem) {
  this.elem      = undefined;
  this.focusElem = focusElem; // picker/select dropdown elem

  this.items = [];

  this.doInit();
  this._bindElem();
}

RomoSelectedOptionsList.prototype.doInit = function() {
  // override as needed
}

/*
Options are specified as a list of items.  Each 'option' item object
has display text and a value. They are compatible with the option list
dropdown option items.

Example:
[ { 'type': 'option', 'value': 'a', 'displayText': 'A' },
  { 'type': 'option', 'value': 'b', 'displayText': 'B' },
  { 'type': 'option', 'value': 'c', 'displayText': 'C' }
]
*/

RomoSelectedOptionsList.prototype.doSetItems = function(itemsList) {
  this.items = itemsList;
}

RomoSelectedOptionsList.prototype.doClearItems = function() {
  this.items = [];
}

RomoSelectedOptionsList.prototype.doAddItem = function(item) {
  if (!this._getItemValues().includes(item.value)) {
    this.items.push(item);
  }
}

RomoSelectedOptionsList.prototype.doRemoveItem = function(itemValue) {
  var index = this._getItemValues().indexOf(itemValue);
  if (index > -1) {
    this.items.splice(index, 1);
  }
}

RomoSelectedOptionsList.prototype.doRefreshUI = function() {
  var itemValues  = this._getItemValues();
  var uiListElem  = this.elem.find('.romo-selected-options-list-items');
  var uiItemElems = uiListElem.find('.romo-selected-options-list-item');
  var uiValues    = uiItemElems.get().map(function(uiItemNode) {
    return $(uiItemNode).data('romo-selected-options-list-value');
  });
  var rmNodes = uiItemElems.get().filter(function(uiItemNode) {
     return itemValues.indexOf($(uiItemNode).data('romo-selected-options-list-value')) === -1;
   });
  var addItems = this.items.filter(function(item) {
    return uiValues.indexOf(item.value) === -1;
  });
  rmNodes.forEach($.proxy(function(rmNode) {
    $(rmNode).remove();
  }, this));
  addItems.forEach($.proxy(function(addItem) {
    var addElem = this._buildItemElem(addItem);
    uiListElem.append(addElem);

    var listWidth       = parseInt(Romo.getComputedStyle(uiListElem[0], "width"), 10);
    var listLeftPad     = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-left"), 10);
    var listRightPad    = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-right"), 10);
    var itemBorderWidth = 1;
    var itemLeftPad     = parseInt(Romo.getComputedStyle(addElem[0], "padding-left"), 10);
    var itemRightPad    = parseInt(Romo.getComputedStyle(addElem[0], "padding-right"), 10);
    addElem.find('DIV').css('max-width', String(listWidth-listLeftPad-listRightPad-(2*itemBorderWidth)-itemLeftPad-itemRightPad)+'px');
  }, this));

  var focusElemWidth = parseInt(Romo.getComputedStyle(this.focusElem[0], "width"), 10);
  this.elem.css('width', String(focusElemWidth)+'px');

  var maxRows          = undefined;
  var uiListElemHeight = parseInt(Romo.getComputedStyle(uiListElem[0], "height"), 10);
  var firstItemNode    = uiListElem.find('.romo-selected-options-list-item')[0];
  if (firstItemNode !== undefined) {
    var itemHeight       = parseInt(Romo.getComputedStyle(firstItemNode, "height"), 10);
    var itemMarginBottom = parseInt(Romo.getComputedStyle(firstItemNode, "margin-bottom"), 10);
    var itemBorderWidth  = 1;
    var listTopPad       = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-top"), 10);
    var listBottomPad    = parseInt(Romo.getComputedStyle(uiListElem[0], "padding-bottom"), 10);

    var maxRows   = this.focusElem.data('romo-selected-options-list-max-rows') || 0;
    var maxHeight = listTopPad+(itemHeight*maxRows)+(itemMarginBottom*(maxRows-1))+(2*itemBorderWidth*maxRows)+listBottomPad+(itemHeight/2);
  }
  if (maxRows !== 0 && (uiListElemHeight > maxHeight)) {
    this.elem.css({
      'height':     String(maxHeight)+'px',
      'overflow-y': 'auto'
    });
    var itemElems    = uiListElem.find('.romo-selected-options-list-item');
    var lastItemNode = itemElems[itemElems.length-1];
    this._scrollListTopToItem($(lastItemNode));
  } else {
    this.elem.css({
      'height':     String(uiListElemHeight)+'px',
      'overflow-y': undefined
    });
  }
}

/* private */

RomoSelectedOptionsList.prototype._bindElem = function() {
  this.elem = $('<div class="romo-selected-options-list"><div class="romo-selected-options-list-items"></div></div>');

  this.elem.on('click', $.proxy(function(e) {
    if (e !== undefined) {
      e.stopPropagation();
{'fraction_non_alphanumeric': 0.1630024428159005, 'fraction_numerical': 0.009882300688429936, 'mean_word_length': 4.425903614457831, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '511710', 'n_tokens_mistral': 3018, 'n_tokens_neox': 2965, 'n_words': 492}