<commit_before>import React from 'react';
import enhanceWithClickOutside from 'react-click-outside';
import { InlineEditContainer, InlineEditInput } from 'ui/components/Mocks/Sidebar/styled';

class InlineEdit extends React.PureComponent {

  componentWillReceiveProps(nextProps) {
    const isEditing = this.props.renamedItemId === nextProps.id;

    if (isEditing) {
      setTimeout(() => {
        if (this.nameInput) {
          this.nameInput.select();
        }
      }, 0);
    }
  }

  handleClickOutside = () => {
    const isEditing = this.props.renamedItemId === this.props.id;

    if (isEditing) {
      this.onCancel();
    }
  };

  handleKeyDown = (event) => {
    const { onCancel, onSave } = this.props;

    switch (event.key) {
      case 'Enter':<commit_msg>Check if inline edit was already in edit mode before selecting the entire text so the user can select a specific place in the input<commit_after>import React from 'react';
import enhanceWithClickOutside from 'react-click-outside';
import { InlineEditContainer, InlineEditInput } from 'ui/components/Mocks/Sidebar/styled';

class InlineEdit extends React.PureComponent {

  componentWillReceiveProps(nextProps) {
    const wasEditing = this.props.id === nextProps.id;
    const isEditing = this.props.renamedItemId === nextProps.id;

    if (isEditing && !wasEditing) {
      setTimeout(() => {
        if (this.nameInput) {
          this.nameInput.select();
        }
      }, 0);
    }
  }

  handleClickOutside = () => {
    const isEditing = this.props.renamedItemId === this.props.id;

    if (isEditing) {
      this.onCancel();
    }
  };

  handleKeyDown = (event) => {
    const { onCancel, onSave } = this.props;

    switch (event.key) {
      case 'Enter':
{'fraction_non_alphanumeric': 0.12414187643020595, 'fraction_numerical': 0.0011441647597254005, 'mean_word_length': 3.067441860465116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1780234', 'n_tokens_mistral': 556, 'n_tokens_neox': 535, 'n_words': 122}