<commit_before>WysiHat.Events = (function() {
  function forwardEvents(document, editor) {
    Event.observe(document, 'mouseup', function(event) {
      editor.fire("wysihat:mouseup");
    });

    Event.observe(document, 'keypress', function(event) {
      editor.fire("wysihat:keypress");
    });

    Event.observe(document, 'keyup', function(event) {
      editor.fire("wysihat:keyup");
    });
  }

  function observePasteEvent(window, document, editor) {
    Event.observe(document, 'keydown', function(event) {
      if (event.keyCode == 86)
        editor.fire("wysihat:paste");
    });

    Event.observe(window, 'paste', function(event) {
      editor.fire("wysihat:paste");
    });
  }

  function observeChanges(document, editor) {
    Event.observe(document, 'keypress', function(event) {
      editor.fire("wysihat:change");
    });

    Event.observe(document, 'keyup', function(event) {
      editor.fire("wysihat:change");
    });
  }

  function observeMovements(document, editor) {
    // Fire the cursormove event if selection has changed due to some event
    var handler = function (event) {
      var rg = editor.selection.getRange();
      if (editor.lastRange != rg) {
        editor.fire("wysihat:cursormove");
        editor.lastRange = rg;
      }
    }

    editor.observe("wysihat:change", handler);
    editor.observe("wysihat:mouseup", handler);
  }

  function observeEvents() {
    if (this.observers_setup)
      return;

    var document = this.getDocument();
    var window = this.getWindow();

    forwardEvents(document, this);
    observePasteEvent(window, document, this);
    observeChanges(document, this);
    observeMovements(document, this);

    this.observers_setup = true;
  }

  return {
    observeEvents: observeEvents
  };
})();

WysiHat.Editor.include(WysiHat.Events);<commit_msg>"wysihat:change" event fires when editor contents changes or cursor position is moved<commit_after>WysiHat.Events = (function() {
  function forwardEvents(document, editor) {
    Event.observe(document, 'mouseup', function(event) {
      editor.fire("wysihat:mouseup");
    });

    Event.observe(document, 'keyup', function(event) {
      editor.fire("wysihat:keyup");
    });
  }

  function observePasteEvent(window, document, editor) {
    Event.observe(document, 'keydown', function(event) {
      if (event.keyCode == 86)
        editor.fire("wysihat:paste");
    });

    Event.observe(window, 'paste', function(event) {
      editor.fire("wysihat:paste");
    });
  }

  function observeChanges(document, editor) {
    Event.observe(document, 'mouseup', function(event) {
      editor.fire("wysihat:change");
    });

    Event.observe(document, 'keyup', function(event) {
      editor.fire("wysihat:change");
    });
  }

  function observeEvents() {
    if (this.observers_setup)
      return;

    var document = this.getDocument();
    var window = this.getWindow();

    forwardEvents(document, this);
    observePasteEvent(window, document, this);
    observeChanges(document, this);

    this.observers_setup = true;
  }

  return {
    observeEvents: observeEvents
  };
})();

WysiHat.Editor.include(WysiHat.Events);
{'fraction_non_alphanumeric': 0.14619513735396275, 'fraction_numerical': 0.0012630249447426586, 'mean_word_length': 3.532188841201717, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401753', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1014, 'n_words': 174}