<commit_before>import React, { Component, PropTypes } from 'react';

class PageContentRow extends Component {
  constructor(props) {
    super(props);
    this.toggleFocus = this.toggleFocus.bind(this);
    this.handleKeyDown = this.handleKeyDown.bind(this);
    this.state = {focus: false};
  }
  toggleFocus() {
    this.setState({ focus: !this.state.focus }, () => {
      if (this.state.focus) {
        this.input.focus();
      }
    });
  }
  handleKeyDown(event) {
    const keyCode = event.keyCode;
    if(keyCode === 13) {
      this.props.onEnterKeyDown(this.props.lineNumber);
      event.preventDefault();
    } else if(keyCode === 8) {
      this.props.onBackSpaceKeyDown(this.props.lineNumber);
      event.preventDefault();
    }
  }
  render() {
    let rowElem =
      this.state.focus ?
      <input
          type="text"
          ref={node => this.input = node}
          value={this.props.text}
          onChange={() => this.props.onChange(this.props.lineNumber, this.input.value)}
          onBlur={this.toggleFocus}
          onKeyDown={this.handleKeyDown}
      />
      :
      <div
          className="cursor-text"
          onClick={this.toggleFocus}
      >
          {this.props.text}
      </div>

    return rowElem;
  }
}
PageContentRow.propTypes = {
  lineNumber: PropTypes.number.isRequired,
  text: PropTypes.string.isRequired,
  onChange: PropTypes.func.isRequired,
  onEnterKeyDown: PropTypes.func,
  onBackSpaceKeyDown: PropTypes.func
};
PageContentRow.defaultProps = {
  text: "",
  onChange: () => {}
};

export default PageContentRow;
<commit_msg>delete line when cursor is at start of line<commit_after>import React, { Component, PropTypes } from 'react';

class PageContentRow extends Component {
  constructor(props) {
    super(props);
    this.toggleFocus = this.toggleFocus.bind(this);
    this.handleKeyDown = this.handleKeyDown.bind(this);
    this.state = {focus: false};
  }
  toggleFocus() {
    this.setState({ focus: !this.state.focus }, () => {
      if (this.state.focus) {
        this.input.focus();
      }
    });
  }
  handleKeyDown(event) {
    const keyCode = event.keyCode;
    if(keyCode === 13) {
      this.props.onEnterKeyDown(this.props.lineNumber);
      event.preventDefault();
    } else if(keyCode === 8) {
      if (this.input.selectionStart === 0) {
        this.props.onBackSpaceKeyDown(this.props.lineNumber);
        event.preventDefault();
      }
    }
  }
  render() {
    let rowElem =
      this.state.focus ?
      <input
          type="text"
          ref={node => this.input = node}
          value={this.props.text}
          onChange={() => this.props.onChange(this.props.lineNumber, this.input.value)}
          onBlur={this.toggleFocus}
          onKeyDown={this.handleKeyDown}
      />
      :
      <div
          className="cursor-text"
          onClick={this.toggleFocus}
      >
          {this.props.text}
      </div>

    return rowElem;
  }
}
PageContentRow.propTypes = {
  lineNumber: PropTypes.number.isRequired,
  text: PropTypes.string.isRequired,
  onChange: PropTypes.func.isRequired,
  onEnterKeyDown: PropTypes.func,
  onBackSpaceKeyDown: PropTypes.func
};
PageContentRow.defaultProps = {
  text: "",
  onChange: () => {}
};

export default PageContentRow;

{'fraction_non_alphanumeric': 0.13857448761089017, 'fraction_numerical': 0.0021413276231263384, 'mean_word_length': 2.613259668508287, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '7562403', 'n_tokens_mistral': 1019, 'n_tokens_neox': 1037, 'n_words': 167}