<commit_before>#= require trix/controllers/controller
#= require trix/controllers/input_controller
#= require trix/controllers/composition_controller
#= require trix/controllers/toolbar_controller
#= require trix/models/selection_manager
#= require trix/models/document
#= require trix/models/composition
#= require trix/models/attachment_manager
#= require trix/models/undo_manager

{rangeIsCollapsed, rangesAreEqual, objectsAreEqual} = Trix

class Trix.EditorController extends Trix.Controller
  constructor: ({@editorElement, document}) ->
    document ?= new Trix.Document

    @selectionManager = new Trix.SelectionManager @editorElement
    @selectionManager.delegate = this

    @composition = new Trix.Composition
    @composition.delegate = this

    @attachmentManager = new Trix.AttachmentManager @composition.getAttachments()
    @attachmentManager.delegate = this

    @undoManager = new Trix.UndoManager @composition

    @inputController = new Trix.InputController @editorElement
    @inputController.delegate = this
    @inputController.responder = @composition

    @compositionController = new Trix.CompositionController @editorElement, @composition
    @compositionController.delegate = this

    @toolbarController = new Trix.ToolbarController @editorElement.toolbarElement
    @toolbarController.delegate = this

    @composition.setDocument(document)
    @render()<commit_msg>Add EditorController#loadHTML, #loadDocument, #loadSnapshot<commit_after>#= require trix/controllers/controller
#= require trix/controllers/input_controller
#= require trix/controllers/composition_controller
#= require trix/controllers/toolbar_controller
#= require trix/models/selection_manager
#= require trix/models/document
#= require trix/models/composition
#= require trix/models/attachment_manager
#= require trix/models/undo_manager

{rangeIsCollapsed, rangesAreEqual, objectsAreEqual} = Trix

class Trix.EditorController extends Trix.Controller
  constructor: ({@editorElement, document, html}) ->
    document ?= new Trix.Document

    @selectionManager = new Trix.SelectionManager @editorElement
    @selectionManager.delegate = this

    @composition = new Trix.Composition
    @composition.delegate = this

    @attachmentManager = new Trix.AttachmentManager @composition.getAttachments()
    @attachmentManager.delegate = this

    @inputController = new Trix.InputController @editorElement
    @inputController.delegate = this
    @inputController.responder = @composition

    @compositionController = new Trix.CompositionController @editorElement, @composition
    @compositionController.delegate = this

    @toolbarController = new Trix.ToolbarController @editorElement.toolbarElement
    @toolbarController.delegate = this

    if document?
      @loadDocument(document)
    else
      @loadHTML(html)

  loadHTML: (html = "") ->
    @loadDocument(Trix.Document.fromHTML(html))

  loadDocument: (document) ->
    @loadSnapshot({document, selectedRange: [0, 0]})

  loadSnapshot: (snapshot) ->
    @undoManager = new Trix.UndoManager @composition
    @composition.restoreSnapshot(snapshot)
{'fraction_non_alphanumeric': 0.09175788795878943, 'fraction_numerical': 0.000643915003219575, 'mean_word_length': 5.1892430278884465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5208146', 'n_tokens_mistral': 855, 'n_tokens_neox': 819, 'n_words': 172}