tor-browser

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

outline.js (1572B)


      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 { showMenu } from "../../context-menu/menu";
      6 import { copyToTheClipboard } from "../../utils/clipboard";
      7 import { findFunctionText } from "../../utils/function";
      8 
      9 import { flashLineRange } from "../../actions/ui";
     10 
     11 import {
     12  getSelectedSource,
     13  getSelectedSourceTextContent,
     14 } from "../../selectors/index";
     15 
     16 export function showOutlineContextMenu(event, func, symbols) {
     17  return async ({ dispatch, getState }) => {
     18    const state = getState();
     19 
     20    const selectedSource = getSelectedSource(state);
     21    if (!selectedSource) {
     22      return;
     23    }
     24    const selectedSourceTextContent = getSelectedSourceTextContent(state);
     25 
     26    const sourceLine = func.location.start.line;
     27    const functionText = findFunctionText(
     28      sourceLine,
     29      selectedSource,
     30      selectedSourceTextContent,
     31      symbols
     32    );
     33 
     34    const copyFunctionItem = {
     35      id: "node-menu-copy-function",
     36      label: L10N.getStr("copyFunction.label"),
     37      accesskey: L10N.getStr("copyFunction.accesskey"),
     38      disabled: !functionText,
     39      click: () => {
     40        dispatch(
     41          flashLineRange({
     42            start: sourceLine,
     43            end: func.location.end.line,
     44            sourceId: selectedSource.id,
     45          })
     46        );
     47        return copyToTheClipboard(functionText);
     48      },
     49    };
     50 
     51    const items = [copyFunctionItem];
     52    showMenu(event, items);
     53  };
     54 }