import React = require("react"); var ReactDOM = require('react-dom'); import csx = require('./base/csx'); import {BaseComponent} from "./ui"; import * as ui from "./ui"; import * as utils from "../common/utils"; import * as styles from "./styles/styles"; import * as state from "./state/state"; import * as commands from "./commands/commands"; import {connect} from "react-redux"; import {Icon} from "./components/icon"; import * as tabRegistry from "./tabs/v2/tabRegistry"; import {tabState,tabStateChanged} from "./tabs/v2/appTabsContainer"; import * as typestyle from "typestyle"; import {extend} from "./base/csx"; let {inputBlackStyleBase} = styles.Input; const inputBlackClassName = typestyle.style(inputBlackStyleBase); export let inputCodeStyle = { fontFamily: 'monospace', } export let searchOptionsLabelStyle = { color: 'grey', fontSize: '1.5rem', fontWeight: 'bold', cursor:'pointer', paddingLeft: '5px', paddingRight: '5px', } let labelStyle = { color: 'grey', padding: '4px' } export interface Props { // connected using redux findQuery?: FindOptions; selectedTabIndex?: number; } export interface State { } @connect((state: state.StoreState): Props => { return { findQuery: state.findOptions, }; }) export class FindAndReplace extends BaseComponent{ componentDidMount() { this.disposible.add(commands.findAndReplace.on(() => { /** Find input might not be there if current tab doesn't support search */ if (!this.findInput()){ return; } // if not shown and the current tab is an editor we should load the selected text from the editor (if any) if (!state.getState().findOptions.isShown) { let codeEditor = tabState.getFocusedCodeEditorIfAny(); if (codeEditor){ const selectedString = codeEditor.getSelectionSearchString(); if (selectedString) { state.setFindOptionsQuery(selectedString); this.findInput().value = selectedString; } } } state.setFindOptionsIsShown(true); this.findInput().select(); this.replaceInput() && this.replaceInput().select(); this.findInput().focus(); })); this.disposible.add(commands.esc.on(() => { state.setFindOptionsIsShown(false); this.findInput() && this.findInput().focus(); })); this.disposible.add(tabStateChanged.on(()=>{ this.forceUpdate(); })); } refs: { [string: string]: any; find: JSX.Element; replace: JSX.Element; regex: {refs:{input: JSX.Element}}; caseInsensitive: {refs:{input: JSX.Element}}; fullWord: {refs:{input: JSX.Element}}; } findInput = (): HTMLInputElement=> ReactDOM.findDOMNode(this.refs.find); replaceInput = (): HTMLInputElement=> ReactDOM.findDOMNode(this.refs.replace); regexInput = (): HTMLInputElement=> ReactDOM.findDOMNode(this.refs.regex.refs.input); caseInsensitiveInput = (): HTMLInputElement=> ReactDOM.findDOMNode(this.refs.caseInsensitive.refs.input); fullWordInput = (): HTMLInputElement=> ReactDOM.findDOMNode(this.refs.fullWord.refs.input); replaceWith = () => this.replaceInput().value; // searchLocation = (): HTMLInputElement=> ReactDOM.findDOMNode(this.refs.find); render() { let shownStyle = this.props.findQuery.isShown ? {} : { display: 'none' }; /** Detect advanced find needed or not */ let tab = tabState.getSelectedTab(); let searchSupport = tab && tabRegistry.getTabConfigByUrl(tab.url).searchSupport; let advancedFind = searchSupport && searchSupport == tabRegistry.TabSearchSupport.Advanced; /** For Find and Replace Multi ... completely bail out */ if (!tab || !searchSupport) { return