<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// @flow
import React, { PureComponent } from "react";
import { connect } from "react-redux";
import classnames from "classnames";
import Svg from "../shared/Svg";
import actions from "../../actions";
import {
  getSelectedSource,
  getPrettySource,
  getPaneCollapse
} from "../../selectors";

import {
  isPretty,
  isLoaded,
  getFilename,
  isOriginal,
  isLoading
} from "../../utils/source";
import { getGeneratedSource } from "../../reducers/sources";
import { shouldShowFooter, shouldShowPrettyPrint } from "../../utils/editor";

import { PaneToggleButton } from "../shared/Button";

import type { Source } from "../../types";

import "./Footer.css";

type CursorPosition = {
  line: number,
  column: number
};

type Props = {
  selectedSource: Source,
  mappedSource: Source,
  endPanelCollapsed: boolean,
  editor: Object,
  horizontal: boolean,
  togglePrettyPrint: string => void,
  toggleBlackBox: Object => void,
  jumpToMappedLocation: (Source: any) => void,
  togglePaneCollapse: () => void
};

type State = {
  cursorPosition: CursorPosition
};

class SourceFooter extends PureComponent<Props, State> {
  constructor() {
    super();

    this.state = { cursorPosition: { line: 1, column: 1 } };
  }

  componentDidMount() {
    const { editor } = this.props;
    editor.codeMirror.on("cursorActivity", this.onCursorChange);
  }

  componentDidUnMount() {
    const { editor } = this.props;
    editor.codeMirror.off("cursorActivity", this.onCursorChange);
  }

  prettyPrintButton() {
    const { selectedSource, togglePrettyPrint } = this.props;

    if (isLoading(selectedSource) && selectedSource.isPrettyPrinted) {
      return (
        <div className="loader">
          <Svg name="loader" />
        </div>
      );
    }

    if (!shouldShowPrettyPrint(selectedSource)) {
      return;
    }

    const tooltip = L10N.getStr("sourceTabs.prettyPrint");
    const sourceLoaded = selectedSource && isLoaded(selectedSource);<commit_msg>Choose proper event to unregister editor cursor activity event (#7378)<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// @flow
import React, { PureComponent } from "react";
import { connect } from "react-redux";
import classnames from "classnames";
import Svg from "../shared/Svg";
import actions from "../../actions";
import {
  getSelectedSource,
  getPrettySource,
  getPaneCollapse
} from "../../selectors";

import {
  isPretty,
  isLoaded,
  getFilename,
  isOriginal,
  isLoading
} from "../../utils/source";
import { getGeneratedSource } from "../../reducers/sources";
import { shouldShowFooter, shouldShowPrettyPrint } from "../../utils/editor";

import { PaneToggleButton } from "../shared/Button";

import type { Source } from "../../types";

import "./Footer.css";

type CursorPosition = {
  line: number,
  column: number
};

type Props = {
  selectedSource: Source,
  mappedSource: Source,
  endPanelCollapsed: boolean,
  editor: Object,
  horizontal: boolean,
  togglePrettyPrint: string => void,
  toggleBlackBox: Object => void,
  jumpToMappedLocation: (Source: any) => void,
  togglePaneCollapse: () => void
};

type State = {
  cursorPosition: CursorPosition
};

class SourceFooter extends PureComponent<Props, State> {
  constructor() {
    super();

    this.state = { cursorPosition: { line: 1, column: 1 } };
  }

  componentDidMount() {
    const { editor } = this.props;
    editor.codeMirror.on("cursorActivity", this.onCursorChange);
  }

  componentWillUnmount() {
    const { editor } = this.props;
    editor.codeMirror.off("cursorActivity", this.onCursorChange);
  }

  prettyPrintButton() {
    const { selectedSource, togglePrettyPrint } = this.props;

    if (isLoading(selectedSource) && selectedSource.isPrettyPrinted) {
      return (
        <div className="loader">
          <Svg name="loader" />
        </div>
      );
    }

    if (!shouldShowPrettyPrint(selectedSource)) {
      return;
    }

    const tooltip = L10N.getStr("sourceTabs.prettyPrint");
    const sourceLoaded = selectedSource && isLoaded(selectedSource);
{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.004522840343735866, 'mean_word_length': 3.4767206477732793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '6516949', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1304, 'n_words': 356}