<commit_before>var ActionTypes = window.CONSTANTS.ActionTypes;
var BountyActionCreators = require('../../actions/bounty_action_creators');
var CommentActionCreators = require('../../actions/comment_action_creators');
var DropzoneMixin = require('../../mixins/dropzone_mixin');
var NewCommentActionCreators = require('../../actions/new_comment_action_creators');
var NewCommentStore = require('../../stores/new_comment_store');
var TypeaheadUserTextArea = require('../typeahead_user_textarea.js.jsx');
var UserStore = require('../../stores/user_store');
var xhr = require('../../xhr');
var ENTER = 13;
var USER_SEARCH_REGEX = /(^|\s)@(\w+)$/

/**
 * TODO: Rethink how this component interacts with its parents and children.
 * Right now, it breaks the one-way flow of data -- is there a better
 * way to pass data in?
 */

var NewsFeedItemNewComment = React.createClass({
  displayName: 'NewComment',

  propTypes: {
    canContainWork: React.PropTypes.bool,
    commentId: _dependsOn('initialText', 'string'),
    hideAvatar: React.PropTypes.bool,
    hideButtons: React.PropTypes.bool,
    initialText: _dependsOn('commentId', 'string'),
    thread: React.PropTypes.string.isRequired,
    url: React.PropTypes.string.isRequired,
    user: React.PropTypes.object
  },

  mixins: [DropzoneMixin],

  buttonClasses: function(btnClass) {
    var classes = {
      disabled: this.state.text.length < 2,
      'pill-button': true,
      'pill-button-theme-white': true,
      'pill-button-border': true,
      'pill-button-shadow': true,
      right: true
    };

    return React.addons.classSet(classes);
  },

  componentDidMount: function() {
    // based on <NAME>'s (@spicyj) work at
    // https://github.com/Khan/react-components/blob/master/js/window-drag.jsx

    // `this._dragCollection` looks weird, but there's a bug in React that
    // causes 'dragenter' to fire twice. By keeping track of elements where the
    // event has fired (instead of the event itself -- see l. 60), we can
    // correctly determine drag behavior.
    this._dragCollection = [];

    window.addEventListener("dragenter", this.onDragEnter);
    window.addEventListener("dragleave", this.onDragLeave);
    window.addEventListener("drop",      this.onDragLeave);

    var domNode = this.getDOMNode();

    domNode.addEventListener('dragenter', this.onDragEnter, false);
    domNode.addEventListener('dragleave', this.onDragLeave, false);
    domNode.addEventListener('drop', this.onDragLeave, false);

    NewCommentStore.addChangeListener(this.getCommentFromStore);
  },

  componentWillUnmount: function() {
    window.removeEventListener("dragenter", this.onDragEnter);
    window.removeEventListener("dragleave", this.onDragLeave);
    window.removeEventListener("drop",      this.onDragLeave);

    var domNode = this.getDOMNode();

    domNode.removeEventListener('dragenter', this.onDragEnter, false);
    domNode.removeEventListener('dragleave', this.onDragLeave, false);
    domNode.removeEventListener('drop', this.onDragLeave, false);

    NewCommentStore.removeChangeListener(this.getCommentFromStore);
  },

  getCommentFromStore: function() {
    this.setState({
      text: NewCommentStore.getComment(this.props.thread)
    });
  },

  getDefaultProps: function() {
    return {
      initialRows: 3,
      user: UserStore.getUser()
    };
  },

  getInitialState: function() {
    return {
      dragging: false,
      rows: this.props.initialRows,
      text: this.props.initialText || ''
    };
  },

  onChange: function(e) {
    NewCommentActionCreators.updateComment(this.props.thread, e.target.value);
  },

  onDragEnter: function(e) {
    if (this._dragCollection.length === 0) {
      this.setState({
        dragging: true
      });
    }

    this._dragCollection = _(this._dragCollection).union([e.target]);
  },

  onDragLeave: function(e) {
    this._dragCollection = _(this._dragCollection).without(e.target);

    if (this._dragCollection.length === 0) {
      this.setState({
        dragging: false
      });
    }
  },

  onKeyDown: function(e) {
    if (this.props.hideButtons) {
      return;
    }

    if ((e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) && e.which === ENTER) {
      e.preventDefault();
      e.stopPropagation();

      this.submitComment(e);
    }
  },

  onKeyPress: function(e) {
    if (this.props.hideButtons) {
      return;
    }

    if ((e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) && e.which === ENTER) {
      e.preventDefault();
      e.stopPropagation();

      this.submitComment(e);
    }
  },
<commit_msg>Don't submit comment on Shift+Enter in NewComment<commit_after>var ActionTypes = window.CONSTANTS.ActionTypes;
var BountyActionCreators = require('../../actions/bounty_action_creators');
var CommentActionCreators = require('../../actions/comment_action_creators');
var DropzoneMixin = require('../../mixins/dropzone_mixin');
var NewCommentActionCreators = require('../../actions/new_comment_action_creators');
var NewCommentStore = require('../../stores/new_comment_store');
var TypeaheadUserTextArea = require('../typeahead_user_textarea.js.jsx');
var UserStore = require('../../stores/user_store');
var xhr = require('../../xhr');
var ENTER = 13;
var USER_SEARCH_REGEX = /(^|\s)@(\w+)$/

/**
 * TODO: Rethink how this component interacts with its parents and children.
 * Right now, it breaks the one-way flow of data -- is there a better
 * way to pass data in?
 */

var NewsFeedItemNewComment = React.createClass({
  displayName: 'NewComment',

  propTypes: {
    canContainWork: React.PropTypes.bool,
    commentId: _dependsOn('initialText', 'string'),
    hideAvatar: React.PropTypes.bool,
    hideButtons: React.PropTypes.bool,
    initialText: _dependsOn('commentId', 'string'),
    thread: React.PropTypes.string.isRequired,
    url: React.PropTypes.string.isRequired,
    user: React.PropTypes.object
  },

  mixins: [DropzoneMixin],

  buttonClasses: function(btnClass) {
    var classes = {
      disabled: this.state.text.length < 2,
      'pill-button': true,
      'pill-button-theme-white': true,
      'pill-button-border': true,
      'pill-button-shadow': true,
      right: true
    };

    return React.addons.classSet(classes);
  },

  componentDidMount: function() {
    // based on <NAME>'s (@spicyj) work at
    // https://github.com/Khan/react-components/blob/master/js/window-drag.jsx

    // `this._dragCollection` looks weird, but there's a bug in React that
    // causes 'dragenter' to fire twice. By keeping track of elements where the
    // event has fired (instead of the event itself -- see l. 60), we can
    // correctly determine drag behavior.
    this._dragCollection = [];

    window.addEventListener("dragenter", this.onDragEnter);
    window.addEventListener("dragleave", this.onDragLeave);
    window.addEventListener("drop",      this.onDragLeave);

    var domNode = this.getDOMNode();

    domNode.addEventListener('dragenter', this.onDragEnter, false);
    domNode.addEventListener('dragleave', this.onDragLeave, false);
    domNode.addEventListener('drop', this.onDragLeave, false);

    NewCommentStore.addChangeListener(this.getCommentFromStore);
  },

  componentWillUnmount: function() {
    window.removeEventListener("dragenter", this.onDragEnter);
    window.removeEventListener("dragleave", this.onDragLeave);
    window.removeEventListener("drop",      this.onDragLeave);

    var domNode = this.getDOMNode();

    domNode.removeEventListener('dragenter', this.onDragEnter, false);
    domNode.removeEventListener('dragleave', this.onDragLeave, false);
    domNode.removeEventListener('drop', this.onDragLeave, false);

    NewCommentStore.removeChangeListener(this.getCommentFromStore);
  },

  getCommentFromStore: function() {
    this.setState({
      text: NewCommentStore.getComment(this.props.thread)
    });
  },

  getDefaultProps: function() {
    return {
      initialRows: 3,
      user: UserStore.getUser()
    };
  },

  getInitialState: function() {
    return {
      dragging: false,
      rows: this.props.initialRows,
      text: this.props.initialText || ''
    };
  },

  onChange: function(e) {
    NewCommentActionCreators.updateComment(this.props.thread, e.target.value);
  },

  onDragEnter: function(e) {
    if (this._dragCollection.length === 0) {
      this.setState({
        dragging: true
      });
    }

    this._dragCollection = _(this._dragCollection).union([e.target]);
  },

  onDragLeave: function(e) {
    this._dragCollection = _(this._dragCollection).without(e.target);

    if (this._dragCollection.length === 0) {
      this.setState({
        dragging: false
      });
    }
  },

  onKeyDown: function(e) {
    if (this.props.hideButtons) {
      return;
    }

    if ((e.metaKey || e.ctrlKey || e.altKey) && e.which === ENTER) {
      e.preventDefault();
      e.stopPropagation();

      this.submitComment(e);
    }
  },

  onKeyPress: function(e) {
    if (this.props.hideButtons) {
      return;
    }

    if ((e.metaKey || e.ctrlKey || e.altKey) && e.which === ENTER) {
      e.preventDefault();
      e.stopPropagation();

      this.submitComment(e);
    }
  },

{'fraction_non_alphanumeric': 0.14357517482517482, 'fraction_numerical': 0.0017482517482517483, 'mean_word_length': 3.3941430628900626, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5394803', 'n_tokens_mistral': 2861, 'n_tokens_neox': 2792, 'n_words': 546}