<commit_before>import { EventDispatcher, Editor, EditorRange, shallowEqual } from '@typewriter/editor';
import { Paper, decorate, getSelection, setSelection, getBounds, getAllBounds, deltaFromHTML } from '@typewriter/view';

import { renderChildren } from './vdom';
import { deltaToVdom, deltaToHTML } from './dom';

const SOURCE_API = 'api';
const SOURCE_USER = 'user';

/**
 * Triggers before each render inside an editor transaction. Respond to this event to add decorations (span elements
 * with the provided attributes at the given ranges).
 *
 * @event View#decorate
 */

/**
 * Triggers right before the view renders the latest contents to the DOM. May pass a change event if the render is
 * triggered by an editor change.
 *
 * @event View#rendering
 */

/**
 * Triggers when the view renders the latest contents to the DOM. May pass a change event if the render is
 * triggered by an editor change.
 *
 * @event View#render
 */

/**
 * Triggers on a keydown event, calling listeners with the keydown event and a shortcut string. These shortcut strings
 * will contain all the modifiers being pressed along with the key. Examples are:
 * Ctrl+B, Ctrl+Shift+Tab, Alt+A, Enter, Shift+Enter, Cmd+Enter, Cmd+Backspace, Space, Tab, Ctrl+Shift+Alt+F11, Ctrl++
 *
 * In addition to the normal modifiers, Cmd, Ctrl, Alt, and Shift, a special modifier called Mod can be used to match
 * Cmd on Mac and Ctrl on other OSes. This allows Mod+B to be used for bold and work correctly on all systems.
 *
 * You can listen for all shortcuts using the "shortcut" event, or you can listen for a specific shortcut using
 * "shortcut:{shortcut}".
 *
 * @event View#shortcut
 * @event View#shortcut:{shortcut} E.g. "shortcut:Mod+Bold"
 */

/**
 * The Typewriter View displays and Editor's contents and selection. The contents are displayed as HTML using a tiny
 * virtual dom implementation and Paper to describe the HTML. The selection is displayed with the native browser
 * selection.
 *
 * View also sends changes to the editor using contenteditable and a mutation observer to capture text entry, keyboard
 * shortcuts to capture other types of edits, and the native selectionchange event to update selection.
 */
export default class View extends EventDispatcher {
  editor: Editor;
  root: HTMLElement;
  paper: Paper;
  modules: { [name: string]: any };
  options: any;
  enabled: boolean;
  private lastSelection?: EditorRange;
  private _settingEditorSelection: boolean;
  private _settingBrowserSelection: boolean;

  /**
   * Create a new View to display an Editor's contents.
   *
   * @param {Editor} editor  A Typewriter editor this View will display the contents for
   * @param {Paper}  paper   The blocks, marks, embeds, and/or container to be used in this editor
   * @param {Object} options Options include:
   *   @param {HTMLElement} root   The root HTML element of this view. If not provided, you must append view.root to the
   *                               DOM yourself
   *   @param {Object} modules     Modules which can be used with this view
   */
  constructor(editor: Editor, paper: Paper, options: any = {}) {
    super(options.catchEventErrors);
    if (!editor) throw new Error('Editor view requires an editor');
    this.editor = editor;
    this.root = options.root || document.createElement('div');
    if (!options.root) this.root.className = 'typewriter-editor';
    this.paper = paper;
    this.enabled = true;
    this.enable();
    this.lastSelection = undefined;
    this._settingEditorSelection = false;
    this._settingBrowserSelection = false;
    this.modules = {};
    this.options = options;
    this.init();<commit_msg>Don't catch errors from view events<commit_after>import { EventDispatcher, Editor, EditorRange, shallowEqual } from '@typewriter/editor';
import { Paper, decorate, getSelection, setSelection, getBounds, getAllBounds, deltaFromHTML } from '@typewriter/view';

import { renderChildren } from './vdom';
import { deltaToVdom, deltaToHTML } from './dom';

const SOURCE_API = 'api';
const SOURCE_USER = 'user';

/**
 * Triggers before each render inside an editor transaction. Respond to this event to add decorations (span elements
 * with the provided attributes at the given ranges).
 *
 * @event View#decorate
 */

/**
 * Triggers right before the view renders the latest contents to the DOM. May pass a change event if the render is
 * triggered by an editor change.
 *
 * @event View#rendering
 */

/**
 * Triggers when the view renders the latest contents to the DOM. May pass a change event if the render is
 * triggered by an editor change.
 *
 * @event View#render
 */

/**
 * Triggers on a keydown event, calling listeners with the keydown event and a shortcut string. These shortcut strings
 * will contain all the modifiers being pressed along with the key. Examples are:
 * Ctrl+B, Ctrl+Shift+Tab, Alt+A, Enter, Shift+Enter, Cmd+Enter, Cmd+Backspace, Space, Tab, Ctrl+Shift+Alt+F11, Ctrl++
 *
 * In addition to the normal modifiers, Cmd, Ctrl, Alt, and Shift, a special modifier called Mod can be used to match
 * Cmd on Mac and Ctrl on other OSes. This allows Mod+B to be used for bold and work correctly on all systems.
 *
 * You can listen for all shortcuts using the "shortcut" event, or you can listen for a specific shortcut using
 * "shortcut:{shortcut}".
 *
 * @event View#shortcut
 * @event View#shortcut:{shortcut} E.g. "shortcut:Mod+Bold"
 */

/**
 * The Typewriter View displays and Editor's contents and selection. The contents are displayed as HTML using a tiny
 * virtual dom implementation and Paper to describe the HTML. The selection is displayed with the native browser
 * selection.
 *
 * View also sends changes to the editor using contenteditable and a mutation observer to capture text entry, keyboard
 * shortcuts to capture other types of edits, and the native selectionchange event to update selection.
 */
export default class View extends EventDispatcher {
  editor: Editor;
  root: HTMLElement;
  paper: Paper;
  modules: { [name: string]: any };
  options: any;
  enabled: boolean;
  private lastSelection?: EditorRange;
  private _settingEditorSelection: boolean;
  private _settingBrowserSelection: boolean;

  /**
   * Create a new View to display an Editor's contents.
   *
   * @param {Editor} editor  A Typewriter editor this View will display the contents for
   * @param {Paper}  paper   The blocks, marks, embeds, and/or container to be used in this editor
   * @param {Object} options Options include:
   *   @param {HTMLElement} root   The root HTML element of this view. If not provided, you must append view.root to the
   *                               DOM yourself
   *   @param {Object} modules     Modules which can be used with this view
   */
  constructor(editor: Editor, paper: Paper, options: any = {}) {
    super();
    if (!editor) throw new Error('Editor view requires an editor');
    this.editor = editor;
    this.root = options.root || document.createElement('div');
    if (!options.root) this.root.className = 'typewriter-editor';
    this.paper = paper;
    this.enabled = true;
    this.enable();
    this.lastSelection = undefined;
    this._settingEditorSelection = false;
    this._settingBrowserSelection = false;
    this.modules = {};
    this.options = options;
    this.init();
{'fraction_non_alphanumeric': 0.08854878382071604, 'fraction_numerical': 0.0005465974309920743, 'mean_word_length': 3.7805355976485955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '220135', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1950, 'n_words': 878}