<commit_before>/*
Copyright 2019 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import PropTypes from 'prop-types';
import { _t } from '../../../languageHandler';
import sdk from '../../../index';


export default class MessageComposerFormatBar extends React.PureComponent {
    static propTypes = {
        onAction: PropTypes.func.isRequired,
        shortcuts: PropTypes.object.isRequired,
    }

    render() {
        return (<div className="mx_MessageComposerFormatBar" ref={ref => this._formatBarRef = ref}>
            <FormatButton shortcut={this.props.shortcuts.bold} label={_t("Bold")} onClick={() => this.props.onAction("bold")} icon="Bold" />
            <FormatButton shortcut={this.props.shortcuts.italics} label={_t("Italics")} onClick={() => this.props.onAction("italics")} icon="Italic" />
            <FormatButton label={_t("Strikethrough")} onClick={() => this.props.onAction("strikethrough")} icon="Strikethrough" />
            <FormatButton label={_t("Code block")} onClick={() => this.props.onAction("code")} icon="Code" />
            <FormatButton shortcut={this.props.shortcuts.quote} label={_t("Quote")} onClick={() => this.props.onAction("quote")} icon="Quote" />
        </div>);
    }

    showAt(selectionRect) {
        this._formatBarRef.classList.add("mx_MessageComposerFormatBar_shown");
        let leftOffset = 0;
        let node = this._formatBarRef;
        while (node.offsetParent) {
            node = node.offsetParent;
            leftOffset += node.offsetLeft;
        }

        let topOffset = 0;
        node = this._formatBarRef;
        while (node.offsetParent) {
            node = node.offsetParent;
            topOffset += node.offsetTop;
        }

        this._formatBarRef.style.left = `${selectionRect.left - leftOffset}px`;
        // 12 is half the height of the bar (e.g. to center it) and 16 is an offset that felt ok.
        this._formatBarRef.style.top = `${selectionRect.top - topOffset - 16 - 12}px`;
    }

    hide() {
        this._formatBarRef.classList.remove("mx_MessageComposerFormatBar_shown");
    }
}
<commit_msg>take bounding box for positioning calculation<commit_after>/*
Copyright 2019 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import PropTypes from 'prop-types';
import { _t } from '../../../languageHandler';
import sdk from '../../../index';


export default class MessageComposerFormatBar extends React.PureComponent {
    static propTypes = {
        onAction: PropTypes.func.isRequired,
        shortcuts: PropTypes.object.isRequired,
    }

    render() {
        return (<div className="mx_MessageComposerFormatBar" ref={ref => this._formatBarRef = ref}>
            <FormatButton shortcut={this.props.shortcuts.bold} label={_t("Bold")} onClick={() => this.props.onAction("bold")} icon="Bold" />
            <FormatButton shortcut={this.props.shortcuts.italics} label={_t("Italics")} onClick={() => this.props.onAction("italics")} icon="Italic" />
            <FormatButton label={_t("Strikethrough")} onClick={() => this.props.onAction("strikethrough")} icon="Strikethrough" />
            <FormatButton label={_t("Code block")} onClick={() => this.props.onAction("code")} icon="Code" />
            <FormatButton shortcut={this.props.shortcuts.quote} label={_t("Quote")} onClick={() => this.props.onAction("quote")} icon="Quote" />
        </div>);
    }

    showAt(selectionRect) {
        this._formatBarRef.classList.add("mx_MessageComposerFormatBar_shown");
        const parentRect = this._formatBarRef.parentElement.getBoundingClientRect();
        this._formatBarRef.style.left = `${selectionRect.left - parentRect.left}px`;
        // 12 is half the height of the bar (e.g. to center it) and 16 is an offset that felt ok.
        this._formatBarRef.style.top = `${selectionRect.top - parentRect.top - 16 - 12}px`;
    }

    hide() {
        this._formatBarRef.classList.remove("mx_MessageComposerFormatBar_shown");
    }
}

{'fraction_non_alphanumeric': 0.13172578716620167, 'fraction_numerical': 0.006775607811877242, 'mean_word_length': 3.3795811518324608, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3104266', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1419, 'n_words': 395}