<commit_before>import React from 'react';
import TextEditor from 'common/components/text-editor';

class WYSIWYGEditor extends React.Component {

  constructor() {
    super();
  }

  focus() {
    this.refs.editor.focus();
  }

  select() {
    this.refs.editor.select();
  }

  onKeyDown(event) {
    var bKey = (event) => {
      if (event.metaKey) {
        console.log('BOLD');
      }
      return false;
    }

    var iKey = (event) => {
      if (event.metaKey) {
        console.log('ITALIC');
      }
      return false;
    }

    var uKey = (event) => {
      console.log(event.metaKey);
      return false;
    }

    var handlers = {
      66: bKey,
      73: iKey,
      85: uKey
    }

    console.log(event.keyCode);

    var handler = handlers[event.keyCode];
    if (handler && handler(event) === false) {
      event.preventDefault();
    }
  }

  shouldComponentUpdate(props) {
    return props.reference.getValue() !== this.refs.editor.source;
  }

  render() {
    var value = this.props.reference.getValue();
    return <TextEditor
      ref='editor'
      {...this.props}
      source={value}
      onKeyDown={this.onKeyDown.bind(this)} />
  }
}

export default WYSIWYGEditor;
<commit_msg>make logic consistent for keys<commit_after>import React from 'react';
import TextEditor from 'common/components/text-editor';

class WYSIWYGEditor extends React.Component {

  constructor() {
    super();
  }

  focus() {
    this.refs.editor.focus();
  }

  select() {
    this.refs.editor.select();
  }

  onKeyDown(event) {
    var bKey = (event) => {
      if (event.metaKey) {
        return;
      }
      return false;
    }

    var iKey = (event) => {
      if (event.metaKey) {
        console.log('ITALIC');
      }
      return false;
    }

    var uKey = (event) => {
      console.log(event.metaKey);
      return false;
    }

    var handlers = {
      66: bKey,
      73: iKey,
      85: uKey
    }

    console.log(event.keyCode);

    var handler = handlers[event.keyCode];
    if (handler && handler(event) !== false) {
      event.preventDefault();
    }
  }

  onChange(source) {
    this.props.reference.setValue(source);
  }

  shouldComponentUpdate(props) {
    return props.reference.getValue() !== this.refs.editor.source;
  }

  render() {
    var value = this.props.reference.getValue();
    return <TextEditor
      ref='editor'
      {...this.props}
      source={value}
      onChange={this.onChange.bind(this)}
      onKeyDown={this.onKeyDown.bind(this)} />
  }
}

export default WYSIWYGEditor;

{'fraction_non_alphanumeric': 0.14538310412573674, 'fraction_numerical': 0.004715127701375246, 'mean_word_length': 2.2936610608020698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6977123', 'n_tokens_mistral': 874, 'n_tokens_neox': 837, 'n_words': 157}