<commit_before>import * as classnames from 'classnames'
import * as React from 'react'

import { propsToDataset } from '../utils/propsToDataset'

interface Props {
    className?: string
    name?: string
    defaultValue?: string
    placeholder?: string
    onChange?: (value: string, dataset: object) => void
    doubleClickToEdit?: boolean
}

interface State {
    readOnly: boolean
    value: string | undefined
}

export default class LabelInput extends React.Component<Props, State>
{
    public static defaultProps = {
        doubleClickToEdit: false,
    }

    public state: State = {
        readOnly: true,
        value: this.props.defaultValue,
    }

    private inputRef = React.createRef<HTMLInputElement>()

    public componentDidUpdate(prevProps: Props, prevState: State) {
        if (prevProps.defaultValue !== this.props.defaultValue) {
            this.setState({ value: this.props.defaultValue })
        }
    }

    public enableAndFocus()
    {
        this.setState({readOnly: false})
        this.inputRef.current!.focus()
        this.inputRef.current!.select()
    }

    public render()
    {
        const {className, name, placeholder} = this.props
        const {value, readOnly} = this.state

        return (
            <input
                ref={this.inputRef}
                type='text'
                tabIndex={-1}
                className={classnames('_label-input', className)}
                name={name}
                value={value}
                placeholder={placeholder}
                readOnly={readOnly}
                onChange={this.valueChanged}
                onKeyDown={this.onKeyDown}
                onBlur={this.onBlur}
                onDoubleClick={this.onDoubleClick}
            />
        )
    }

    private onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) =>
    {
        const {onChange, defaultValue} = this.props
        const input = this.inputRef.current!
        const dataset = propsToDataset(this.props)

        if (e.key === 'Enter') {
            if (this.state.readOnly) {
                this.enableAndFocus()
            } else {
                onChange && onChange(input.value, dataset)
                this.setState({readOnly: true, value: input.value})
            }
        } else if (e.key === 'Escape') {
            onChange && onChange(input.value, dataset)
            this.setState({readOnly: true, value: defaultValue || ''})
        }
    }<commit_msg>Ignoring Enter key in composed<commit_after>import * as classnames from 'classnames'
import * as React from 'react'

import { propsToDataset } from '../utils/propsToDataset'

interface Props {
    className?: string
    name?: string
    defaultValue?: string
    placeholder?: string
    onChange?: (value: string, dataset: object) => void
    doubleClickToEdit?: boolean
}

interface State {
    readOnly: boolean
    value: string | undefined
}

export default class LabelInput extends React.Component<Props, State>
{
    public static defaultProps = {
        doubleClickToEdit: false,
    }

    public state: State = {
        readOnly: true,
        value: this.props.defaultValue,
    }

    private inputRef = React.createRef<HTMLInputElement>()

    public componentDidUpdate(prevProps: Props, prevState: State) {
        if (prevProps.defaultValue !== this.props.defaultValue) {
            this.setState({ value: this.props.defaultValue })
        }
    }

    public enableAndFocus()
    {
        this.setState({readOnly: false})
        this.inputRef.current!.focus()
        this.inputRef.current!.select()
    }

    public render()
    {
        const {className, name, placeholder} = this.props
        const {value, readOnly} = this.state

        return (
            <input
                ref={this.inputRef}
                type='text'
                tabIndex={-1}
                className={classnames('_label-input', className)}
                name={name}
                value={value}
                placeholder={placeholder}
                readOnly={readOnly}
                onChange={this.valueChanged}
                onKeyDown={this.onKeyDown}
                onBlur={this.onBlur}
                onDoubleClick={this.onDoubleClick}
            />
        )
    }

    private onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) =>
    {
        const {onChange, defaultValue} = this.props
        const input = this.inputRef.current!
        const dataset = propsToDataset(this.props)

        if (e.key === 'Enter' && !(e.nativeEvent as any).isComposing) {
            if (this.state.readOnly) {
                this.enableAndFocus()
            } else {
                onChange && onChange(input.value, dataset)
                this.setState({readOnly: true, value: input.value})
            }
        } else if (e.key === 'Escape') {
            onChange && onChange(input.value, dataset)
            this.setState({readOnly: true, value: defaultValue || ''})
        }
    }
{'fraction_non_alphanumeric': 0.1106425702811245, 'fraction_numerical': 0.00040160642570281126, 'mean_word_length': 1.980849790544584, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '811596', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1332, 'n_words': 293}