<commit_before>import React = require("react");
import ReactDOM = require("react-dom");
import Radium = require('radium');
import csx = require('csx');
import {BaseComponent} from "../ui";
import * as ui from "../ui";
var Modal = require('react-modal');
import * as styles from "../styles/styles";
import {debounce,createMap,rangeLimited,getFileName} from "../../common/utils";
import {cast, server} from "../../socket/socketClient";
import * as commands from "../commands/commands";
import {match, filter as fuzzyFilter} from "fuzzaldrin";
import {Icon} from "../icon";
import {TypedEvent} from "../../common/events";
import * as state from "../state/state";
import * as types from "../../common/types";

/** Stuff shared by the select list view */
import {renderMatchedSegments, keyStrokeStyle, getFilteredItems} from ".././selectListView";

export interface Props {
}
export interface State {
}

enum SearchMode {
    /** Use if the user does something like `👎>` i.e. invalid mode key */
    Unknown,
    File,
    Command,
    Project,
}

let inputStyle = {
    backgroundColor: 'rgb(42,42,42)',
    color: 'white',
    outline: 'none',
    padding: '2px',
    fontSize: '1.5rem',
    lineHeight: '2rem',
    fontFamily: 'monospace',

    border: '3px solid #3C3C3C',
    transition: 'border .2s',
    ':focus':{
        boxShadow: '0px 0px 1px 1px #3C3C3C'
    }
}
let selectedStyle = {
    background: '#545454',
    color: 'white'
};
let listItemStyle = {
    fontFamily: 'monospace'
};

let searchingNameStyle = { marginTop: '0', marginBottom: '0', marginLeft: '10px', border: '1px solid grey', padding: '4px 4px', background: 'black' };


@ui.Radium
export class OmniSearch extends BaseComponent<Props, State>{
    mode: SearchMode = SearchMode.File;

    searchState = new SearchState();

    constructor(props: Props) {
        super(props);

        this.searchState.stateChanged.on(() => this.forceUpdate());
        this.searchState.setParentUiRawFilterValue = (value) => {
            this.setRawFilterValue(value);
        };

        this.state = this.propsToState(props);
    }

    propsToState(props: Props): State {
        return {
        };
    }
    componentWillReceiveProps(props: Props) {
        this.setState(this.propsToState(props));
    }

    refs: {
        [string: string]: any;
        omniSearch: any;
        omniSearchInput: any;

        selected: Element;
    }

    componentDidMount() {
        commands.omniFindFile.on(() => {
            this.searchState.openOmniSearch(SearchMode.File);
        });
        commands.omniFindCommand.on(() => {
            this.searchState.openOmniSearch(SearchMode.Command);
        });
        commands.omniSelectProject.on(() => {
            this.searchState.openOmniSearch(SearchMode.Project);
        });
    }

    componentDidUpdate() {
        // get the dom node that is selected
        // make sure its parent scrolls to make this visible
        setTimeout(()=>{
            if (this.refs.selected) {
                let selected = ReactDOM.findDOMNode(this.refs.selected) as HTMLDivElement;
                selected.scrollIntoViewIfNeeded(false);
            }
            // also keep the input in focus
            if (this.searchState.isShown) {
                let input = (ReactDOM.findDOMNode(this.refs.omniSearchInput) as HTMLInputElement)
                input.focus();
                let len = input.value.length;
                input.setSelectionRange(len, len)
            }
        });
    }

    render() {<commit_msg>omni : only scroll to end if it wasn't shown before<commit_after>import React = require("react");
import ReactDOM = require("react-dom");
import Radium = require('radium');
import csx = require('csx');
import {BaseComponent} from "../ui";
import * as ui from "../ui";
var Modal = require('react-modal');
import * as styles from "../styles/styles";
import {debounce,createMap,rangeLimited,getFileName} from "../../common/utils";
import {cast, server} from "../../socket/socketClient";
import * as commands from "../commands/commands";
import {match, filter as fuzzyFilter} from "fuzzaldrin";
import {Icon} from "../icon";
import {TypedEvent} from "../../common/events";
import * as state from "../state/state";
import * as types from "../../common/types";

/** Stuff shared by the select list view */
import {renderMatchedSegments, keyStrokeStyle, getFilteredItems} from ".././selectListView";

export interface Props {
}
export interface State {
}

enum SearchMode {
    /** Use if the user does something like `👎>` i.e. invalid mode key */
    Unknown,
    File,
    Command,
    Project,
}

let inputStyle = {
    backgroundColor: 'rgb(42,42,42)',
    color: 'white',
    outline: 'none',
    padding: '2px',
    fontSize: '1.5rem',
    lineHeight: '2rem',
    fontFamily: 'monospace',

    border: '3px solid #3C3C3C',
    transition: 'border .2s',
    ':focus':{
        boxShadow: '0px 0px 1px 1px #3C3C3C'
    }
}
let selectedStyle = {
    background: '#545454',
    color: 'white'
};
let listItemStyle = {
    fontFamily: 'monospace'
};

let searchingNameStyle = { marginTop: '0', marginBottom: '0', marginLeft: '10px', border: '1px solid grey', padding: '4px 4px', background: 'black' };


@ui.Radium
export class OmniSearch extends BaseComponent<Props, State>{
    mode: SearchMode = SearchMode.File;

    searchState = new SearchState();

    constructor(props: Props) {
        super(props);

        this.searchState.stateChanged.on(() => this.forceUpdate());
        this.searchState.setParentUiRawFilterValue = (value) => {
            this.setRawFilterValue(value);
        };

        this.state = this.propsToState(props);
    }

    propsToState(props: Props): State {
        return {
        };
    }
    componentWillReceiveProps(props: Props) {
        this.setState(this.propsToState(props));
    }

    refs: {
        [string: string]: any;
        omniSearch: any;
        omniSearchInput: any;

        selected: Element;
    }

    componentDidMount() {
        commands.omniFindFile.on(() => {
            this.searchState.openOmniSearch(SearchMode.File);
        });
        commands.omniFindCommand.on(() => {
            this.searchState.openOmniSearch(SearchMode.Command);
        });
        commands.omniSelectProject.on(() => {
            this.searchState.openOmniSearch(SearchMode.Project);
        });
    }

    wasShown = false;
    componentWillUpdate(){
        this.wasShown = this.searchState.isShown;
    }

    componentDidUpdate() {
        // get the dom node that is selected
        // make sure its parent scrolls to make this visible
        setTimeout(()=>{
            if (this.refs.selected) {
                let selected = ReactDOM.findDOMNode(this.refs.selected) as HTMLDivElement;
                selected.scrollIntoViewIfNeeded(false);
            }
            // also keep the input in focus
            if (this.searchState.isShown) {
                let input = (ReactDOM.findDOMNode(this.refs.omniSearchInput) as HTMLInputElement)
                input.focus();

                // and scroll to the end if its just been shown
                if (!this.wasShown){
                    let len = input.value.length;
                    input.setSelectionRange(len, len);
                    this.wasShown = true;
                }
            }
        });
    }

    render() {
{'fraction_non_alphanumeric': 0.136110734156602, 'fraction_numerical': 0.009499253630071923, 'mean_word_length': 2.4912363808621505, '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': '6698867', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2146, 'n_words': 538}