<commit_before>import Ember from 'ember';

var get = Ember.get;

/*
  Holds a stack of key responder views. With this we can neatly handle
  restoring the previous key responder when some modal UI element is closed.
  There are a few simple rules that governs the usage of the stack:
   - mouse click does .replace (this should also be used for programmatically taking focus when not a modal element)
   - opening a modal UI element does .push
   - closing a modal element does .pop

  Also noteworthy is that a view will be signaled that it loses the key focus
  only when it's popped off the stack, not when something is pushed on top. The
  idea is that when a modal UI element is opened, we know that the previously
  focused view will re-gain the focus as soon as the modal element is closed.
  So if the previously focused view was e.g. in the middle of some edit
  operation, it shouldn't cancel that operation.
*/
var KeyResponder = Ember.ArrayProxy.extend({
  init: function() {
    this.set('isActive', true);
    this.set('content', Ember.A());
    this._super.apply(this, arguments);
  },

  current: Ember.computed.readOnly('lastObject'),
  pushView: function(view, wasTriggeredByFocus) {
    if (!Ember.isNone(view)) {
      view.trigger('willBecomeKeyResponder', wasTriggeredByFocus);
      this.pushObject(view);
      view.trigger('didBecomeKeyResponder', wasTriggeredByFocus);
    }
    return view;
  },

  resume: function() {
    this.set('isActive', true);
  },

  pause: function() {
    this.set('isActive', false);
  },

  popView: function(wasTriggeredByFocus) {
    if (get(this, 'length') > 0) {
      var view = get(this, 'current');
      if (view) {
        view.trigger('willLoseKeyResponder', wasTriggeredByFocus);
      }
      view = this.popObject();
      view.trigger('didLoseKeyResponder', wasTriggeredByFocus);
      return view;
    } else {
      return undefined;
    }
  },

  replaceView: function(view, wasTriggeredByFocus) {
    if (get(this, 'current') !== view) {
      this.popView(wasTriggeredByFocus);
      return this.pushView(view, wasTriggeredByFocus);
    }
  }
});

export default KeyResponder;

export var KEY_EVENTS = {
  8: 'deleteBackward',
  9: 'insertTab',
  13: 'insertNewline',
  27: 'cancel',
  32: 'insertSpace',
  37: 'moveLeft',
  38: 'moveUp',
  39: 'moveRight',
  40: 'moveDown',
  46: 'deleteForward'
};

export var MODIFIED_KEY_EVENTS = {
  8: 'deleteForward',<commit_msg>Check for view before sending it a message<commit_after>import Ember from 'ember';

var get = Ember.get;

/*
  Holds a stack of key responder views. With this we can neatly handle
  restoring the previous key responder when some modal UI element is closed.
  There are a few simple rules that governs the usage of the stack:
   - mouse click does .replace (this should also be used for programmatically taking focus when not a modal element)
   - opening a modal UI element does .push
   - closing a modal element does .pop

  Also noteworthy is that a view will be signaled that it loses the key focus
  only when it's popped off the stack, not when something is pushed on top. The
  idea is that when a modal UI element is opened, we know that the previously
  focused view will re-gain the focus as soon as the modal element is closed.
  So if the previously focused view was e.g. in the middle of some edit
  operation, it shouldn't cancel that operation.
*/
var KeyResponder = Ember.ArrayProxy.extend({
  init: function() {
    this.set('isActive', true);
    this.set('content', Ember.A());
    this._super.apply(this, arguments);
  },

  current: Ember.computed.readOnly('lastObject'),
  pushView: function(view, wasTriggeredByFocus) {
    if (!Ember.isNone(view)) {
      view.trigger('willBecomeKeyResponder', wasTriggeredByFocus);
      this.pushObject(view);
      view.trigger('didBecomeKeyResponder', wasTriggeredByFocus);
    }
    return view;
  },

  resume: function() {
    this.set('isActive', true);
  },

  pause: function() {
    this.set('isActive', false);
  },

  popView: function(wasTriggeredByFocus) {
    if (get(this, 'length') > 0) {
      var view = get(this, 'current');
      if (view) {
        view.trigger('willLoseKeyResponder', wasTriggeredByFocus);
      }
      view = this.popObject();
      if (view) {
        view.trigger('didLoseKeyResponder', wasTriggeredByFocus);
      }
      return view;
    } else {
      return undefined;
    }
  },

  replaceView: function(view, wasTriggeredByFocus) {
    if (get(this, 'current') !== view) {
      this.popView(wasTriggeredByFocus);
      return this.pushView(view, wasTriggeredByFocus);
    }
  }
});

export default KeyResponder;

export var KEY_EVENTS = {
  8: 'deleteBackward',
  9: 'insertTab',
  13: 'insertNewline',
  27: 'cancel',
  32: 'insertSpace',
  37: 'moveLeft',
  38: 'moveUp',
  39: 'moveRight',
  40: 'moveDown',
  46: 'deleteForward'
};

export var MODIFIED_KEY_EVENTS = {
  8: 'deleteForward',
{'fraction_non_alphanumeric': 0.10870883006668014, 'fraction_numerical': 0.00808244089715094, 'mean_word_length': 3.4275491949910553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6773245', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1533, 'n_words': 514}