<commit_before>import ListSelection from './list-selection';

const COPY = {};

export default class FilePatchSelection {
  constructor(hunks) {
    if (hunks._copy !== COPY) {
      // Initialize a new selection
      this.mode = 'hunk';

      this.hunksByLine = new Map();
      const lines = [];
      for (const hunk of hunks) {
        for (const line of hunk.lines) {
          lines.push(line);
          this.hunksByLine.set(line, hunk);
        }
      }

      this.hunksSelection = new ListSelection({items: hunks});
      // TODO: investigate if there's a better fix for line.isChanged error after discarding
      this.linesSelection = new ListSelection({
        items: lines,
        isItemSelectable: line => line && line.isChanged(),
      });
      this.resolveNextUpdatePromise = () => {};
    } else {
      // Copy from options. *Only* reachable from the copy() method because no other module has visibility to
      // the COPY object without shenanigans.
      const options = hunks;

      this.mode = options.mode;
      this.hunksSelection = options.hunksSelection;
      this.linesSelection = options.linesSelection;
      this.resolveNextUpdatePromise = options.resolveNextUpdatePromise;
      this.hunksByLine = options.hunksByLine;
    }
  }

  copy(options = {}) {
    const mode = options.mode || this.mode;
    const hunksSelection = options.hunksSelection || this.hunksSelection.copy();
    const linesSelection = options.linesSelection || this.linesSelection.copy();

    let hunksByLine = null;
    if (options.hunks) {
      // Update hunks<commit_msg>Remove quick fix for the line is undefined error<commit_after>import ListSelection from './list-selection';

const COPY = {};

export default class FilePatchSelection {
  constructor(hunks) {
    if (hunks._copy !== COPY) {
      // Initialize a new selection
      this.mode = 'hunk';

      this.hunksByLine = new Map();
      const lines = [];
      for (const hunk of hunks) {
        for (const line of hunk.lines) {
          lines.push(line);
          this.hunksByLine.set(line, hunk);
        }
      }

      this.hunksSelection = new ListSelection({items: hunks});
      this.linesSelection = new ListSelection({
        items: lines,
        isItemSelectable: line => line.isChanged(),
      });
      this.resolveNextUpdatePromise = () => {};
    } else {
      // Copy from options. *Only* reachable from the copy() method because no other module has visibility to
      // the COPY object without shenanigans.
      const options = hunks;

      this.mode = options.mode;
      this.hunksSelection = options.hunksSelection;
      this.linesSelection = options.linesSelection;
      this.resolveNextUpdatePromise = options.resolveNextUpdatePromise;
      this.hunksByLine = options.hunksByLine;
    }
  }

  copy(options = {}) {
    const mode = options.mode || this.mode;
    const hunksSelection = options.hunksSelection || this.hunksSelection.copy();
    const linesSelection = options.linesSelection || this.linesSelection.copy();

    let hunksByLine = null;
    if (options.hunks) {
      // Update hunks
{'fraction_non_alphanumeric': 0.10886319845857419, 'fraction_numerical': 0.0, 'mean_word_length': 2.6863905325443787, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '799135', 'n_tokens_mistral': 909, 'n_tokens_neox': 867, 'n_words': 232}