tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

file-search.js (1558B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 import { searchSourceForHighlight } from "../utils/editor/index";
      6 
      7 import {
      8  getSelectedSourceTextContent,
      9  getSearchOptions,
     10 } from "../selectors/index";
     11 
     12 import { closeActiveSearch, clearHighlightLineRange } from "./ui";
     13 
     14 export function doSearchForHighlight(query, editor) {
     15  return async ({ getState, dispatch }) => {
     16    const sourceTextContent = getSelectedSourceTextContent(getState());
     17    if (!sourceTextContent) {
     18      return;
     19    }
     20 
     21    dispatch(searchContentsForHighlight(query, editor));
     22  };
     23 }
     24 
     25 // Expose an action to the React component, so that it can call the searchWorker.
     26 export function querySearchWorker(query, text, modifiers) {
     27  return ({ searchWorker }) => {
     28    return searchWorker.getMatches(query, text, modifiers);
     29  };
     30 }
     31 
     32 export function searchContentsForHighlight(query, editor) {
     33  return async ({ getState }) => {
     34    const modifiers = getSearchOptions(getState(), "file-search");
     35    const sourceTextContent = getSelectedSourceTextContent(getState());
     36 
     37    if (!query || !editor || !sourceTextContent || !modifiers) {
     38      return;
     39    }
     40 
     41    const ctx = { editor, cm: editor.codeMirror };
     42    searchSourceForHighlight(ctx, false, query, true, modifiers);
     43  };
     44 }
     45 
     46 export function closeFileSearch() {
     47  return ({ dispatch }) => {
     48    dispatch(closeActiveSearch());
     49    dispatch(clearHighlightLineRange());
     50  };
     51 }