<commit_before>const _ = require("underscore-plus")

module.exports = class SearchHistoryManager {
  constructor(vimState) {
    this.vimState = vimState
    this.globalState = vimState.globalState

    this.reset()
    vimState.onDidDestroy(() => this.destroy())
  }

  get(direction) {
    const {limitNumber} = this.vimState.utils

    switch (direction) {
      case "prev":
        this.index = limitNumber(this.index + 1, {max: this.getSize() - 1})
        break
      case "next":
        this.index = limitNumber(this.index - 1, {min: -1})
        break
    }
    const entry = this.globalState.get("searchHistory")[this.index]
    console.log("index", this.index, entry)
    return entry != null ? entry : ""
  }

  save(entry) {
    if (_.isEmpty(entry)) return

    let entries = this.vimState.globalState.get("searchHistory").slice()
    entries.unshift(entry)
    entries = _.uniq(entries)
    if (this.getSize() > this.vimState.getConfig("historySize")) {
      entries.splice(this.vimState.getConfig("historySize"))
    }
    this.globalState.set("searchHistory", entries)
  }

  reset() {
    this.index = -1
  }

  clear() {
    this.globalState.reset("searchHistory")
  }

  getSize() {<commit_msg>:fire: leftover<commit_after>const _ = require("underscore-plus")

module.exports = class SearchHistoryManager {
  constructor(vimState) {
    this.vimState = vimState
    this.globalState = vimState.globalState

    this.reset()
    vimState.onDidDestroy(() => this.destroy())
  }

  get(direction) {
    const {limitNumber} = this.vimState.utils

    switch (direction) {
      case "prev":
        this.index = limitNumber(this.index + 1, {max: this.getSize() - 1})
        break
      case "next":
        this.index = limitNumber(this.index - 1, {min: -1})
        break
    }
    const entry = this.globalState.get("searchHistory")[this.index]
    return entry != null ? entry : ""
  }

  save(entry) {
    if (_.isEmpty(entry)) return

    let entries = this.vimState.globalState.get("searchHistory").slice()
    entries.unshift(entry)
    entries = _.uniq(entries)
    if (this.getSize() > this.vimState.getConfig("historySize")) {
      entries.splice(this.vimState.getConfig("historySize"))
    }
    this.globalState.set("searchHistory", entries)
  }

  reset() {
    this.index = -1
  }

  clear() {
    this.globalState.reset("searchHistory")
  }

  getSize() {
{'fraction_non_alphanumeric': 0.14728033472803348, 'fraction_numerical': 0.0041841004184100415, 'mean_word_length': 2.991652754590985, 'pattern_counts': {'":': 4, '<': 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': '4414050', 'n_tokens_mistral': 798, 'n_tokens_neox': 757, 'n_words': 134}