src/search/FindReplace.js
function openSearchBar(editor, replace) {
        var cm = editor._codeMirror,
            state = getSearchState(cm);

        // Use the selection start as the searchStartPos. This way if you
        // start with a pre-populated search and enter an additional character,
        // it will extend the initial selection instead of jumping to the next
        // occurrence.
        state.searchStartPos = editor.getCursorPos(false, "start");

        // Prepopulate the search field
        var initialQuery = FindBar.getInitialQuery(findBar, editor);
        if (initialQuery.query === "" && editor.lastParsedQuery !== "") {
            initialQuery.query = editor.lastParsedQuery;
        }

        // Close our previous find bar, if any. (The open() of the new findBar will
        // take care of closing any other find bar instances.)
        if (findBar) {
            findBar.close();
        }

        // Create the search bar UI (closing any previous find bar in the process)
        findBar = new FindBar({
            multifile: false,
            replace: replace,
            initialQuery: initialQuery.query,
            initialReplaceText: initialQuery.replaceText,
            queryPlaceholder: Strings.FIND_QUERY_PLACEHOLDER
        });
        findBar.open();

        findBar
            .on("queryChange.FindReplace", function (e) {
                handleQueryChange(editor, state);
            })
            .on("doFind.FindReplace", function (e, searchBackwards) {
                findNext(editor, searchBackwards);
            })
            .on("close.FindReplace", function (e) {
                editor.lastParsedQuery = state.parsedQuery;
                // Clear highlights but leave search state in place so Find Next/Previous work after closing
                clearHighlights(cm, state);

                // Dispose highlighting UI (important to restore normal selection color as soon as focus goes back to the editor)
                toggleHighlighting(editor, false);

                findBar.off(".FindReplace");
                findBar = null;
            });

        handleQueryChange(editor, state, true);
    }
function openSearchBar(editor, replace) {
        var cm = editor._codeMirror,
            state = getSearchState(cm);

        // Use the selection start as the searchStartPos. This way if you
        // start with a pre-populated search and enter an additional character,
        // it will extend the initial selection instead of jumping to the next
        // occurrence.
        state.searchStartPos = editor.getCursorPos(false, "start");

        // Prepopulate the search field
        var initialQuery = FindBar.getInitialQuery(findBar, editor);
        if (initialQuery.query === "" && editor.lastParsedQuery !== "") {
            initialQuery.query = editor.lastParsedQuery;
        }

        // Close our previous find bar, if any. (The open() of the new findBar will
        // take care of closing any other find bar instances.)
        if (findBar) {
            findBar.close();
        }

        // Create the search bar UI (closing any previous find bar in the process)
        findBar = new FindBar({
            multifile: false,
            replace: replace,
            initialQuery: initialQuery.query,
            initialReplaceText: initialQuery.replaceText,
            queryPlaceholder: Strings.FIND_QUERY_PLACEHOLDER
        });
        findBar.open();

        findBar
            .on("queryChange.FindReplace", function (e) {
                handleQueryChange(editor, state);
            })
            .on("doFind.FindReplace", function (e, searchBackwards) {
                findNext(editor, searchBackwards);
            })
            .on("close.FindReplace", function (e) {
                editor.lastParsedQuery = state.parsedQuery;
                // Clear highlights but leave search state in place so Find Next/Previous work after closing
                clearHighlights(cm, state);

                // Dispose highlighting UI (important to restore normal selection color as soon as focus goes back to the editor)
                toggleHighlighting(editor, false);

                findBar.off(".FindReplace");
                findBar = null;
            });

        handleQueryChange(editor, state, true);
    }
function openSearchBar ( editor , replace ) { var cm = editor . _codeMirror , state = getSearchState ( cm ) ; // Use the selection start as the searchStartPos. This way if you // start with a pre-populated search and enter an additional character, // it will extend the initial selection instead of jumping to the next // occurrence. state . searchStartPos = editor . getCursorPos ( false , "start" ) ; // Prepopulate the search field var initialQuery = FindBar . getInitialQuery ( findBar , editor ) ; if ( initialQuery . query === "" && editor . lastParsedQuery !== "" ) { initialQuery . query = editor . lastParsedQuery ; } // Close our previous find bar, if any. (The open() of the new findBar will // take care of closing any other find bar instances.) if ( findBar ) { findBar . close ( ) ; } // Create the search bar UI (closing any previous find bar in the process) findBar = new FindBar ( { multifile : false , replace : replace , initialQuery : initialQuery . query , initialReplaceText : initialQuery . replaceText , queryPlaceholder : Strings . FIND_QUERY_PLACEHOLDER } ) ; findBar . open ( ) ; findBar . on ( "queryChange.FindReplace" , function ( e ) { handleQueryChange ( editor , state ) ; } ) . on ( "doFind.FindReplace" , function ( e , searchBackwards ) { findNext ( editor , searchBackwards ) ; } ) . on ( "close.FindReplace" , function ( e ) { editor . lastParsedQuery = state . parsedQuery ; // Clear highlights but leave search state in place so Find Next/Previous work after closing clearHighlights ( cm , state ) ; // Dispose highlighting UI (important to restore normal selection color as soon as focus goes back to the editor) toggleHighlighting ( editor , false ) ; findBar . off ( ".FindReplace" ) ; findBar = null ; } ) ; handleQueryChange ( editor , state , true ) ; }
Creates a Find bar for the current search session.
@param {!Editor} editor
@param {boolean} replace Whether to show the Replace UI; default false
Creates a Find bar for the current search session .