<commit_before>#= require trix/utilities/object
#= require trix/models/block
#= require trix/models/splittable_list
#= require trix/models/location_range

class Trix.Document extends Trix.Object
  @fromJSON: (documentJSON) ->
    blocks = for blockJSON in documentJSON
      Trix.Block.fromJSON blockJSON
    new this blocks

  @fromHTML: (html, options) ->
    Trix.HTMLParser.parse(html, options).getDocument()

  @fromString: (string, textAttributes) ->
    text = Trix.Text.textForStringWithAttributes(string, textAttributes)
    new this [new Trix.Block text]

  constructor: (blocks = []) ->
    super
    @editDepth = 0
    @editCount = 0
    @blockList = new Trix.SplittableList blocks

  copy: ->
    new @constructor @blockList.toArray()

  edit = (name, fn) -> ->
    @beginEditing()
    fn.apply(this, arguments)

    console.group(name)
    console.log(format(object)...) for object in arguments
    console.groupEnd()

    @endEditing()

  format = (object) ->
    if (value = object?.toConsole?())?
      ["%o%c%s%c", object, "color: #888", value, "color: auto"]
    else if typeof object is "string"
      ["%s", object]
    else
      ["%o", object]

  edit: edit "edit", (fn) -> fn()

  beginEditing: ->
    if @editDepth++ is 0
      @editCount++
      console.group("Edit operation #{@editCount}")
      console.groupCollapsed("Backtrace")
      console.trace()
      console.groupEnd()
    this

  endEditing: ->
    if --@editDepth is 0
      console.groupEnd()
      @delegate?.didEditDocument?(this)
    this

  insertDocumentAtLocationRange: edit "insertDocumentAtLocationRange", (document, locationRange) ->
    block = @getBlockAtIndex(locationRange.index)

    position = @blockList.findPositionAtIndexAndOffset(locationRange.index, locationRange.offset)
    position++ if locationRange.end.offset is block.getBlockBreakPosition()

    @removeTextAtLocationRange(locationRange)<commit_msg>Log document id with edit operations<commit_after>#= require trix/utilities/object
#= require trix/models/block
#= require trix/models/splittable_list
#= require trix/models/location_range

class Trix.Document extends Trix.Object
  @fromJSON: (documentJSON) ->
    blocks = for blockJSON in documentJSON
      Trix.Block.fromJSON blockJSON
    new this blocks

  @fromHTML: (html, options) ->
    Trix.HTMLParser.parse(html, options).getDocument()

  @fromString: (string, textAttributes) ->
    text = Trix.Text.textForStringWithAttributes(string, textAttributes)
    new this [new Trix.Block text]

  constructor: (blocks = []) ->
    super
    @editDepth = 0
    @editCount = 0
    @blockList = new Trix.SplittableList blocks

  copy: ->
    new @constructor @blockList.toArray()

  edit = (name, fn) -> ->
    @beginEditing()
    fn.apply(this, arguments)

    console.group(name)
    console.log(format(object)...) for object in arguments
    console.groupEnd()

    @endEditing()

  format = (object) ->
    if (value = object?.toConsole?())?
      ["%o%c%s%c", object, "color: #888", value, "color: auto"]
    else if typeof object is "string"
      ["%s", object]
    else
      ["%o", object]

  edit: edit "edit", (fn) -> fn()

  beginEditing: ->
    if @editDepth++ is 0
      @editCount++
      console.group("Document #{@id}: Edit operation #{@editCount}")
      console.groupCollapsed("Backtrace")
      console.trace()
      console.groupEnd()
    this

  endEditing: ->
    if --@editDepth is 0
      console.groupEnd()
      @delegate?.didEditDocument?(this)
    this

  insertDocumentAtLocationRange: edit "insertDocumentAtLocationRange", (document, locationRange) ->
    block = @getBlockAtIndex(locationRange.index)

    position = @blockList.findPositionAtIndexAndOffset(locationRange.index, locationRange.offset)
    position++ if locationRange.end.offset is block.getBlockBreakPosition()

    @removeTextAtLocationRange(locationRange)
{'fraction_non_alphanumeric': 0.1298399586990191, 'fraction_numerical': 0.0036138358286009293, 'mean_word_length': 3.4953596287703017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '5085854', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1173, 'n_words': 276}