<commit_before>let classnames = require('classnames');
let deepcopy = require('deepcopy');
let React = require('react'); 
let ReactDOM = require('react-dom');

class Transfer extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            chosen: props.data.filter(function(item) {return !!item.chosen}),
            unChosen: props.data.filter(function(item) {return !item.chosen})
        }
    }

    componentDidMount() {
        let me = this;
    }

    componentWillReceiveProps(nextProps) {
        let me = this;
        if (!me._isEqual(nextProps.data, me.props.data)) {
            me.setState({
                chosen: nextProps.data.filter(function(item) {return !!item.chosen}),
                unChosen: nextProps.data.filter(function(item) {return !item.chosen})
            })
        }
    }

    _isEqual(a, b) {
        return JSON.stringify(a) == JSON.stringify(b)
    }


    /**
     * 抽取 arr1 的一部分给 arr2，返回变换后的两个数组
     * @param {array} arr1
     * @param {array} arr2
     */

    selectItems(arr) {
        let me = this;
        let data = deepcopy(this.state);
        data.chosen.forEach((item, index) => {
            if (arr.indexOf(item.value) != -1) {
                item.selected = true;
            }
        });
        data.unChosen.forEach((item, index) => {
            if (arr.indexOf(item.value) != -1) {
                item.selected = true;
            }
        });
        me.setState(data);
    }

    /**
     * 重置，取消所有的用户操作
     */

    reset() {
        let me = this;
        me.setState({
            chosen: me.props.data.filter(function(item) {return !!item.chosen}),
            unChosen: me.props.data.filter(function(item) {return !item.chosen})
        });
    }

    locateItem(value, position) {
        let data = me.state[position];
        let leftBlock = me.refs.leftBlock;
        let leftBlockEl = ReactDOM.findDOMNode(leftBlock);
        let rightBlock = me.refs.rightBlock;
        let rightBlockEl = ReactDOM.findDOMNode(rightBlock);
        let index;
        for (let i = 0; i < data.length; i++) {
            if (data[i].name.indexOf(value) !== -1) {
                index = i;
                break;
            }
            if (data[i].keywords instanceof Array) {
                let keywords = data[i].keywords;
                for (let j = 0; j < keywords.length; j++) {
                    if (keywords[j].indexOf(value) !== -1) {
                        index = i;
                        break;
                    }
                }
                if (index != undefined) break;
            }
        }
        if (index != undefined) {
            if (position == 'unChosen') {
                leftBlockEl.scrollTop = 30 * index;
            }
            else {
                rightBlock.scrollTop = 30 * index;
            }
        }
    }

    _handleSearchIconClick(position) {<commit_msg>增加搜索定位后高亮支持<commit_after>let classnames = require('classnames');
let deepcopy = require('deepcopy');
let React = require('react'); 
let ReactDOM = require('react-dom');
class Transfer extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            chosen: props.data.filter(function(item) {return !!item.chosen}),
            unChosen: props.data.filter(function(item) {return !item.chosen})
        }
    }

    componentDidMount() {
        let me = this;
    }

    componentWillReceiveProps(nextProps) {
        let me = this;
        if (!me._isEqual(nextProps.data, me.props.data)) {
            me.setState({
                chosen: nextProps.data.filter(function(item) {return !!item.chosen}),
                unChosen: nextProps.data.filter(function(item) {return !item.chosen})
            })
        }
    }

    _isEqual(a, b) {
        return JSON.stringify(a) == JSON.stringify(b)
    }


    /**
     * 抽取 arr1 的一部分给 arr2，返回变换后的两个数组
     * @param {array} arr1
     * @param {array} arr2
     */

    selectItems(arr) {
        let me = this;
        let data = deepcopy(this.state);
        data.chosen.forEach((item, index) => {
            if (arr.indexOf(item.value) != -1) {
                item.selected = true;
            }
        });
        data.unChosen.forEach((item, index) => {
            if (arr.indexOf(item.value) != -1) {
                item.selected = true;
            }
        });
        me.setState(data);
    }

    /**
     * 重置，取消所有的用户操作
     */

    reset() {
        let me = this;
        me.setState({
            chosen: me.props.data.filter(function(item) {return !!item.chosen}),
            unChosen: me.props.data.filter(function(item) {return !item.chosen})
        });
    }

    locateItem(value, position) {
        let data = deepcopy( me.state[position] );
        let leftBlock = me.refs.leftBlock;
        let leftBlockEl = ReactDOM.findDOMNode(leftBlock);
        let rightBlock = me.refs.rightBlock;
        let rightBlockEl = ReactDOM.findDOMNode(rightBlock);
        let index;
        for (let i = 0; i < data.length; i++) {
             data[i].justMoved = false;
        }
        for (let i = 0; i < data.length; i++) {
            if (data[i].name.indexOf(value) !== -1) {
                index = i;
                break;
            }
            if (data[i].keywords instanceof Array) {
                let keywords = data[i].keywords;
                for (let j = 0; j < keywords.length; j++) {
                    if (keywords[j].indexOf(value) !== -1) {
                        index = i;
                        break;
                    }
                }
                if (index != undefined) break;
            }
        }
        if (index !== undefined && value !== '') {
            data[index].justMoved = true;
            if (position == 'unChosen') {
                leftBlockEl.scrollTop = 30 * index;
            }
            else {
                rightBlock.scrollTop = 30 * index;
            }
        }
        var obj ={};
        obj[position] = data;
        this.setState( obj );
    }

    _handleSearchIconClick(position) {
{'fraction_non_alphanumeric': 0.13371616078753076, 'fraction_numerical': 0.00475799835931091, 'mean_word_length': 1.5284114475321444, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '5063070', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1828, 'n_words': 355}