<commit_before>import React from "react";
import ReactDOM from "react-dom";
import DragDrop from "../DragDrop.js";
import Orientation from "../Orientation.js";
import BorderNode from "../model/BorderNode.js";
import Actions from "../model/Actions.js";

class Splitter extends React.Component {

    onMouseDown(event) {
        DragDrop.instance.startDrag(event, this.onDragStart.bind(this), this.onDragMove.bind(this), this.onDragEnd.bind(this), this.onDragCancel.bind(this));
    }

    onDragCancel() {
        let rootdiv = ReactDOM.findDOMNode(this.props.layout);
        rootdiv.removeChild(this.outlineDiv);
    }

    onDragStart(event) {
        this.pBounds = this.props.node.getParent()._getSplitterBounds(this.props.node);
        let rootdiv = ReactDOM.findDOMNode(this.props.layout);
        this.outlineDiv = document.createElement("div");
        this.outlineDiv.style.position = "absolute";
        this.outlineDiv.className = "flexlayout__splitter_drag";
        this.outlineDiv.style.cursor = this.props.node.getOrientation() === Orientation.HORZ ? "ns-resize" : "ew-resize";
        this.props.node.getRect().positionElement(this.outlineDiv);
        rootdiv.appendChild(this.outlineDiv);
        return true;
    }

    onDragMove(event) {
        let clientRect = ReactDOM.findDOMNode(this.props.layout).getBoundingClientRect();
        let pos = {
            x: event.clientX - clientRect.left,
            y: event.clientY - clientRect.top
        };

        if (this.props.node.getOrientation() === Orientation.HORZ) {
            this.outlineDiv.style.top = this.getBoundPosition(pos.y - 4) + "px";
        }
        else {
            this.outlineDiv.style.left = this.getBoundPosition(pos.x - 4) + "px";
        }
    }

    onDragEnd(event) {
        let node = this.props.node;
        let value = 0;
        if (node.getOrientation() === Orientation.HORZ) {
            value = this.outlineDiv.offsetTop;
        }
        else {
            value = this.outlineDiv.offsetLeft;
        }

        if (node.getParent().getType() == BorderNode.TYPE) {
            let pos = node.getParent()._calculateSplit(node, value);
            this.props.layout.doAction(Actions.adjustBorderSplit(node.getParent().getId(), pos));
        }
        else {
            let splitSpec = node.getParent()._calculateSplit(this.props.node, value);
            this.props.layout.doAction(Actions.adjustSplit(splitSpec));
        }

        let rootdiv = ReactDOM.findDOMNode(this.props.layout);
        rootdiv.removeChild(this.outlineDiv);
    }

    getBoundPosition(p) {
        let rtn = p;
        if (p < this.pBounds[0]) {
            rtn = this.pBounds[0];
        }
        if (p > this.pBounds[1]) {
            rtn = this.pBounds[1];
        }

        return rtn;
    }

    render() {
        let node = this.props.node;
        let style = node._styleWithPosition(
            {
                cursor: this.props.node.getOrientation() === Orientation.HORZ ? "ns-resize" : "ew-resize"
            }
        );

        return <div style={style} onTouchStart={this.onMouseDown.bind(this)} onMouseDown={this.onMouseDown.bind(this)}
                    className="flexlayout__splitter"></div>;
    }
}

export default Splitter;<commit_msg>tidy code<commit_after>import React from "react";
import ReactDOM from "react-dom";
import DragDrop from "../DragDrop.js";
import Orientation from "../Orientation.js";
import BorderNode from "../model/BorderNode.js";
import Actions from "../model/Actions.js";

class Splitter extends React.Component {

    onMouseDown(event) {
        DragDrop.instance.startDrag(event, this.onDragStart.bind(this), this.onDragMove.bind(this), this.onDragEnd.bind(this), this.onDragCancel.bind(this));
    }

    onDragCancel() {
        let rootdiv = ReactDOM.findDOMNode(this.props.layout);
        rootdiv.removeChild(this.outlineDiv);
    }

    onDragStart(event) {
        this.pBounds = this.props.node.getParent()._getSplitterBounds(this.props.node);
        let rootdiv = ReactDOM.findDOMNode(this.props.layout);
        this.outlineDiv = document.createElement("div");
        this.outlineDiv.style.position = "absolute";
        this.outlineDiv.className = "flexlayout__splitter_drag";
        this.outlineDiv.style.cursor = this.props.node.getOrientation() === Orientation.HORZ ? "ns-resize" : "ew-resize";
        this.props.node.getRect().positionElement(this.outlineDiv);
        rootdiv.appendChild(this.outlineDiv);
        return true;
    }

    onDragMove(event) {
        let clientRect = ReactDOM.findDOMNode(this.props.layout).getBoundingClientRect();
        let pos = {
            x: event.clientX - clientRect.left,
            y: event.clientY - clientRect.top
        };

        if (this.props.node.getOrientation() === Orientation.HORZ) {
            this.outlineDiv.style.top = this.getBoundPosition(pos.y - 4) + "px";
        }
        else {
            this.outlineDiv.style.left = this.getBoundPosition(pos.x - 4) + "px";
        }
    }

    onDragEnd(event) {
        let node = this.props.node;
        let value = 0;
        if (node.getOrientation() === Orientation.HORZ) {
            value = this.outlineDiv.offsetTop;
        }
        else {
            value = this.outlineDiv.offsetLeft;
        }

        if (node.getParent().getType() == BorderNode.TYPE) {
            let pos = node.getParent()._calculateSplit(node, value);
            this.props.layout.doAction(Actions.adjustBorderSplit(node.getParent().getId(), pos));
        }
        else {
            let splitSpec = node.getParent()._calculateSplit(this.props.node, value);
            if (splitSpec != null) {
                this.props.layout.doAction(Actions.adjustSplit(splitSpec));
            }
        }

        let rootdiv = ReactDOM.findDOMNode(this.props.layout);
        rootdiv.removeChild(this.outlineDiv);
    }

    getBoundPosition(p) {
        let rtn = p;
        if (p < this.pBounds[0]) {
            rtn = this.pBounds[0];
        }
        if (p > this.pBounds[1]) {
            rtn = this.pBounds[1];
        }

        return rtn;
    }

    render() {
        let node = this.props.node;
        let style = node._styleWithPosition(
            {
                cursor: this.props.node.getOrientation() === Orientation.HORZ ? "ns-resize" : "ew-resize"
            }
        );

        return <div style={style} onTouchStart={this.onMouseDown.bind(this)} onMouseDown={this.onMouseDown.bind(this)}
                    className="flexlayout__splitter"></div>;
    }
}

export default Splitter;
{'fraction_non_alphanumeric': 0.1332319391634981, 'fraction_numerical': 0.002129277566539924, 'mean_word_length': 2.3045226130653265, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '728649', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1974, 'n_words': 313}