<commit_before>/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */

import { Arr, Type } from '@ephox/katamari';
import { AddOnManager } from './AddOnManager';
import { Editor } from './Editor';
import Env from './Env';
import ErrorReporter from '../ErrorReporter';
import DOMUtils from './dom/DOMUtils';
import DomQuery from './dom/DomQuery';
import FocusController from '../focus/FocusController';
import I18n from './util/I18n';
import Observable from './util/Observable';
import Promise from './util/Promise';
import Tools from './util/Tools';
import URI from './util/URI';
import { document } from '@ephox/dom-globals';

declare const window: any;

/**
 * This class used as a factory for manager for tinymce.Editor instances.
 *
 * @example
 * tinymce.EditorManager.init({});
 *
 * @class tinymce.EditorManager
 * @mixes tinymce.util.Observable
 * @static
 */

const DOM = DOMUtils.DOM;
const explode = Tools.explode, each = Tools.each, extend = Tools.extend;
let instanceCounter = 0, beforeUnloadDelegate, EditorManager, boundGlobalEvents = false;
const legacyEditors = [];
let editors = [];

const isValidLegacyKey = function (id) {
  // In theory we could filter out any editor id:s that clash
  // with array prototype items but that could break existing integrations
  return id !== 'length';
};

const globalEventDelegate = function (e) {
  each(EditorManager.get(), function (editor) {
    if (e.type === 'scroll') {
      editor.fire('ScrollWindow', e);
    } else {
      editor.fire('ResizeWindow', e);
    }
  });
};

const toggleGlobalEvents = function (state) {
  if (state !== boundGlobalEvents) {
    if (state) {
      DomQuery(window).on('resize scroll', globalEventDelegate);
    } else {
      DomQuery(window).off('resize scroll', globalEventDelegate);
    }

    boundGlobalEvents = state;
  }
};

const removeEditorFromList = function (targetEditor: Editor) {
  const oldEditors = editors;

  delete legacyEditors[targetEditor.id];
  for (let i = 0; i < legacyEditors.length; i++) {
    if (legacyEditors[i] === targetEditor) {
      legacyEditors.splice(i, 1);<commit_msg>TINY-3247: Fixed an issue where scrolling with multiple editors would cause a ResizeWindow event to fire<commit_after>/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */

import { Arr, Type } from '@ephox/katamari';
import { AddOnManager } from './AddOnManager';
import { Editor } from './Editor';
import Env from './Env';
import ErrorReporter from '../ErrorReporter';
import DOMUtils from './dom/DOMUtils';
import DomQuery from './dom/DomQuery';
import FocusController from '../focus/FocusController';
import I18n from './util/I18n';
import Observable from './util/Observable';
import Promise from './util/Promise';
import Tools from './util/Tools';
import URI from './util/URI';
import { document } from '@ephox/dom-globals';

declare const window: any;

/**
 * This class used as a factory for manager for tinymce.Editor instances.
 *
 * @example
 * tinymce.EditorManager.init({});
 *
 * @class tinymce.EditorManager
 * @mixes tinymce.util.Observable
 * @static
 */

const DOM = DOMUtils.DOM;
const explode = Tools.explode, each = Tools.each, extend = Tools.extend;
let instanceCounter = 0, beforeUnloadDelegate, EditorManager, boundGlobalEvents = false;
const legacyEditors = [];
let editors = [];

const isValidLegacyKey = function (id) {
  // In theory we could filter out any editor id:s that clash
  // with array prototype items but that could break existing integrations
  return id !== 'length';
};

const globalEventDelegate = function (e) {
  const type = e.type;
  each(EditorManager.get(), function (editor) {
    switch (type) {
      case 'scroll':
        editor.fire('ScrollWindow', e);
        break;
      case 'resize':
        editor.fire('ResizeWindow', e);
        break;
    }
  });
};

const toggleGlobalEvents = function (state) {
  if (state !== boundGlobalEvents) {
    if (state) {
      DomQuery(window).on('resize scroll', globalEventDelegate);
    } else {
      DomQuery(window).off('resize scroll', globalEventDelegate);
    }

    boundGlobalEvents = state;
  }
};

const removeEditorFromList = function (targetEditor: Editor) {
  const oldEditors = editors;

  delete legacyEditors[targetEditor.id];
  for (let i = 0; i < legacyEditors.length; i++) {
    if (legacyEditors[i] === targetEditor) {
      legacyEditors.splice(i, 1);
{'fraction_non_alphanumeric': 0.12951301427371956, 'fraction_numerical': 0.003778337531486146, 'mean_word_length': 3.8622448979591835, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1869536', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1376, 'n_words': 453}