<commit_before>export default class ChangeHistoryView {
  constructor (documentSession) {
    this.documentSession = documentSession
    this._undo = []
    this._redo = []
  }

  canUndo () {
    return this._undo.length > 0
  }

  canRedo () {
    return this._redo.length > 0
  }

  commit (change, info) {
    let idx = this.documentSession._history.length
    this.documentSession._commitChange(change, info)
    this._undo.push(idx)
    // whenever a change is committed via this view
    // then undone is cleared, i.e. these changes can not be redone
    this._redo.length = 0
  }

  undo () {
    if (this._undo.length === 0) return
    const history = this.documentSession._history
    let newIdx = history.length
    // take the last index of done
    let idx = this._undo.pop()
    let change
    try {
      change = this.documentSession.revert(idx)
      this._redo.push(newIdx)
    } catch (err) {
      this._undo.push(idx)
    }
    return change
  }

  redo () {
    if (this._redo.length === 0) return
    const history = this.documentSession._history
    let newIdx = history.length
    // take the last index of done
    let idx = this._redo.pop()
    let change
    try {
      change = this.documentSession.revert(idx)
      this._undo.push(newIdx)
    } catch (err) {
      this._redo.push(idx)
    }
    return change
  }

  reset () {
    this._undo.length = 0
    this._redo.length = 0
  }
}<commit_msg>Log error when undo/redo fails.<commit_after>export default class ChangeHistoryView {
  constructor (documentSession) {
    this.documentSession = documentSession
    this._undo = []
    this._redo = []
  }

  canUndo () {
    return this._undo.length > 0
  }

  canRedo () {
    return this._redo.length > 0
  }

  commit (change, info) {
    let idx = this.documentSession._history.length
    this.documentSession._commitChange(change, info)
    this._undo.push(idx)
    // whenever a change is committed via this view
    // then undone is cleared, i.e. these changes can not be redone
    this._redo.length = 0
  }

  undo () {
    if (this._undo.length === 0) return
    const history = this.documentSession._history
    let newIdx = history.length
    // take the last index of done
    let idx = this._undo.pop()
    let change
    try {
      change = this.documentSession.revert(idx)
      this._redo.push(newIdx)
    } catch (err) {
      console.error(err)
      this._undo.push(idx)
    }
    return change
  }

  redo () {
    if (this._redo.length === 0) return
    const history = this.documentSession._history
    let newIdx = history.length
    // take the last index of done
    let idx = this._redo.pop()
    let change
    try {
      change = this.documentSession.revert(idx)
      this._undo.push(newIdx)
    } catch (err) {
      console.error(err)
      this._redo.push(idx)
    }
    return change
  }

  reset () {
    this._undo.length = 0
    this._redo.length = 0
  }
}
{'fraction_non_alphanumeric': 0.10860655737704918, 'fraction_numerical': 0.0047814207650273225, 'mean_word_length': 2.3474285714285714, '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': '4907942', 'n_tokens_mistral': 959, 'n_tokens_neox': 928, 'n_words': 236}