<commit_before>import React, { Component } from 'react';
import unionClassNames from 'union-class-names';
import removeBlock from './modifiers/removeBlock';

// Get a component's display name
const getDisplayName = (WrappedComponent) => {
  const component = WrappedComponent.WrappedComponent || WrappedComponent;
  return component.displayName || component.name || 'Component';
};

export default ({ theme, store }) => (WrappedComponent) => class BlockFocusDecorator extends Component {
  static displayName = `BlockFocus(${getDisplayName(WrappedComponent)})`;
  static WrappedComponent = WrappedComponent.WrappedComponent || WrappedComponent;

  componentWillMount() {
    store.subscribeToItem('selection', this.onSelectionChanged);
  }

  componentWillUnmount() {
    const { isFocused } = this.props.blockProps;
    this.componentWillUpdate();
    if (isFocused) {
      this.props.blockProps.unsetFocus();
    }
  }

  // onSelectionChanged = (selection) => {
  onSelectionChanged = () => {
    // TODO only update if something changed
    this.forceUpdate();
  }

  // TODO fix this with left/right up down
  releaseOnKeyDown = (event) => {
    if (event.keyCode === 38) {
      this.props.blockProps.unsetFocus('up', event);
    } else if (event.keyCode === 40) {
      this.props.blockProps.unsetFocus('down', event);
    } else if (event.keyCode === 8) {
      // TODO fix backspace for removing the block
      this.props.blockProps.unsetFocus('down', event);
      store.setEditorState(removeBlock(store, this.props.block.get('key')));
    }
  }

  releaseOnClick = () => {
    // TODO don't release in case it's inside this component
    this.props.blockProps.unsetFocus();
  }

  render() {
    const { blockProps, className } = this.props;
    const { isFocused } = blockProps;
    const combinedClassName = isFocused()
      ? unionClassNames(className, theme.focused)
      : unionClassNames(className, theme.unfocused);
    return (
      <WrappedComponent
        {...this.props}
        className={combinedClassName}
      />
    );
  }
};
<commit_msg>cleanup focus decorator<commit_after>import React, { Component } from 'react';
import unionClassNames from 'union-class-names';
import removeBlock from './modifiers/removeBlock';

// Get a component's display name
const getDisplayName = (WrappedComponent) => {
  const component = WrappedComponent.WrappedComponent || WrappedComponent;
  return component.displayName || component.name || 'Component';
};

export default ({ theme, store }) => (WrappedComponent) => class BlockFocusDecorator extends Component {
  static displayName = `BlockFocus(${getDisplayName(WrappedComponent)})`;
  static WrappedComponent = WrappedComponent.WrappedComponent || WrappedComponent;

  componentWillMount() {
    store.subscribeToItem('selection', this.onSelectionChanged);
  }

  componentWillUnmount() {
    store.unsubscribeFromItem('selection', this.onSelectionChanged);
  }

  // onSelectionChanged = (selection) => {
  onSelectionChanged = () => {
    // TODO only update if something changed
    this.forceUpdate();
  }

  // TODO fix this with left/right up down
  releaseOnKeyDown = (event) => {
    if (event.keyCode === 38) {
      this.props.blockProps.unsetFocus('up', event);
    } else if (event.keyCode === 40) {
      this.props.blockProps.unsetFocus('down', event);
    } else if (event.keyCode === 8) {
      // TODO fix backspace for removing the block
      this.props.blockProps.unsetFocus('down', event);
      store.setEditorState(removeBlock(store, this.props.block.get('key')));
    }
  }

  releaseOnClick = () => {
    // TODO don't release in case it's inside this component
    this.props.blockProps.unsetFocus();
  }

  render() {
    const { blockProps, className } = this.props;
    const { isFocused } = blockProps;
    const combinedClassName = isFocused()
      ? unionClassNames(className, theme.focused)
      : unionClassNames(className, theme.unfocused);
    return (
      <WrappedComponent
        {...this.props}
        className={combinedClassName}
      />
    );
  }
};

{'fraction_non_alphanumeric': 0.1291431377363123, 'fraction_numerical': 0.0024551927326295114, 'mean_word_length': 3.624290578887628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '1359559', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1153, 'n_words': 259}