<commit_before>_ = require 'underscore'

# Internal: The object in charge of managing redo and undo operations.
module.exports =
class UndoManager
  undoHistory: null
  redoHistory: null
  currentTransaction: null

  constructor: ->
    @clear()

  clear: ->
    @currentTransaction = null
    @undoHistory = []
    @redoHistory = []

  pushOperation: (operation, editSession) ->
    if @currentTransaction
      @currentTransaction.push(operation)
    else
      @undoHistory.push([operation])
    @redoHistory = []

    try
      operation.do?(editSession)
    catch e
      @clear()
      throw e

  transact: ->
    isNewTransaction = not @currentTransaction?
    @currentTransaction ?= []
    isNewTransaction

  commit: ->
    unless @currentTransaction?
      throw new Error("Trying to commit when there is no current transaction")<commit_msg>Make UndoManager.clear not cancel the transaction<commit_after>_ = require 'underscore'

# Internal: The object in charge of managing redo and undo operations.
module.exports =
class UndoManager
  undoHistory: null
  redoHistory: null
  currentTransaction: null

  constructor: ->
    @clear()

  clear: ->
    @currentTransaction = [] if @currentTransaction?
    @undoHistory = []
    @redoHistory = []

  pushOperation: (operation, editSession) ->
    if @currentTransaction
      @currentTransaction.push(operation)
    else
      @undoHistory.push([operation])
    @redoHistory = []

    try
      operation.do?(editSession)
    catch e
      @clear()
      throw e

  transact: ->
    isNewTransaction = not @currentTransaction?
    @currentTransaction ?= []
    isNewTransaction

  commit: ->
    unless @currentTransaction?
      throw new Error("Trying to commit when there is no current transaction")
{'fraction_non_alphanumeric': 0.09488636363636363, 'fraction_numerical': 0.0, 'mean_word_length': 3.223021582733813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '331370', 'n_tokens_mistral': 495, 'n_tokens_neox': 478, 'n_words': 137}