<commit_before>angular.module('bgDirectives', [])
    .directive('bgSplitter', function()
    {
        return {
            restrict: 'E',
            require: '?^bgPane',
            replace: true,
            transclude: true,
            scope: {
                orientation: '@',
                pos: '@',
                size: '@'
        },
        template: '<div class="split-panes {{orientation}}" ng-transclude></div>',
        controller: ['$scope', '$element', '$attrs', function (scope, element, attrs)
        {
            this.scope = scope;
            scope.panes = [];

            this.addPane = function(pane)
            {
                if (scope.panes.length > 1)
                {
                   throw 'splitters can only have two panes';
                }
                scope.panes.push(pane);
                return scope.panes.length;
            };

            scope.getStyleRule = function(selector, sheet)
            {
                var sheets = typeof sheet !== 'undefined' ? [sheet] : document.styleSheets;
                for (var i = 0, l = sheets.length; i < l; i++)
                {
                    var sheet = sheets[i];
                    if( !sheet.cssRules )
                    {
                        continue;
                    }
                    for (var j = 0, k = sheet.cssRules.length; j < k; j++)
                    {
                        var rule = sheet.cssRules[j];
                        if (rule.selectorText && rule.selectorText.split(',').indexOf(selector) !== -1)
                        {
                            return rule.style;
                        }
                    }
                }
                return null;
            }

            var orientation = this.scope.orientation;
            var isVertical = this.scope.isVertical = orientation == 'vertical';

            // get the size of the splitter from the pane2 border and its hitzone from split-handler
            var borderStyle = scope.getStyleRule('.split-panes.'+ orientation +' > .split-pane2');
            var border = isVertical? borderStyle['border-left']: borderStyle['border-top'];
            var sizePx = border.split(' ')[0];
            var splitterSize = parseInt(sizePx.substring(0, sizePx.indexOf('px')));


            // adjust handler size
            if (this.scope.size)
            {
                splitterSize = Number(scope.size);
            }

            this.scope.splitterSize = splitterSize;
        }],
        link: {
            pre: function preLink(scope, element, attrs, bgPane)
            {
                function calcSizes(scope, width, height)
                {
                    scope.width = width;
                    scope.height = height;

                    scope.paneSizes = [];
                    var range = scope.isVertical ? width : height;
                    var val = 0;

                    var pos = scope.pos;

                    if (pos == null)
                    {
                        pos = "50%";
                    }


                    if (pos.indexOf('%') != -1)
                    {
                        // handle percent
                        var posStr = pos.substring(0, pos.indexOf('%'));
                        var fraction = Number(posStr) / 100;

                        val = range * fraction | 0;
                        val = val < 0 ? range + val - scope.splitterSize : val;
                    }
                    else
                    {
                        // handle pixels
                        var pixels = parseInt(pos);
                        val = pixels < 0 ? range + pixels - scope.splitterSize: pixels;
                    }

                    if (scope.isVertical)
                    {
                        scope.paneSizes.push([val, height], [width - val, height]);
                        scope.startX = val;
                    }
                    else
                    {
                        scope.paneSizes.push([width, val], [width, height - val]);
                        scope.startY = val;
                    }
                }

                // calculate the width and height of each pane
                if (bgPane)
                {
                    var width = bgPane.scope.paneSize[0];
                    var height = bgPane.scope.paneSize[1];
                    calcSizes(scope, width, height);
                }
                else
                {
                    var bounds = element[0].getBoundingClientRect();
                    var width = bounds.right - bounds.left;
                    var height = bounds.bottom - bounds.top;
                    calcSizes(scope, width, height);
                }
            },
            post: function postLink (scope, element, attrs, bgPane)
            {
                var handler = angular.element('<div class="split-handler"></div>');
                var pane1 = scope.panes[0];
                var pane2 = scope.panes[1];
                var pane1Min = pane1.minSize || 0;
                var pane2Min = pane2.minSize || 0;
                var drag = false;

                pane1.elem.after(handler);


                function resize (ev)
                {
                    if (!drag) return;

                    var bounds = element[0].getBoundingClientRect();
                    var pos = 0;

                    if (scope.isVertical)
                    {
                        var width = bounds.right - bounds.left;
                        pos = ev.clientX - bounds.left;

                        if (pos < pane1Min) return;
                        if (width - pos < pane2Min) return;

                        handler.css('left', pos + 'px');
                        pane1.elem.css('width', pos + 'px');
                        pane2.elem.css('left', pos + 'px');

                    } else {
                        var height = bounds.bottom - bounds.top;
                        pos = ev.clientY - bounds.top;

                        if (pos < pane1Min) return;
                        if (height - pos < pane2Min) return;

                        handler.css('top', pos + 'px');
                        pane1.elem.css('height', pos + 'px');
                        pane2.elem.css('top', pos + 'px');
                    }<commit_msg>Instead of not responding when dragging the splitter beyond the minimum size, clamp to the valid range.<commit_after>angular.module('bgDirectives', [])
    .directive('bgSplitter', function()
    {
        return {
            restrict: 'E',
            require: '?^bgPane',
            replace: true,
            transclude: true,
            scope: {
                orientation: '@',
                pos: '@',
                size: '@'
        },
        template: '<div class="split-panes {{orientation}}" ng-transclude></div>',
        controller: ['$scope', '$element', '$attrs', function (scope, element, attrs)
        {
            this.scope = scope;
            scope.panes = [];

            this.addPane = function(pane)
            {
                if (scope.panes.length > 1)
                {
                   throw 'splitters can only have two panes';
                }
                scope.panes.push(pane);
                return scope.panes.length;
            };

            scope.getStyleRule = function(selector, sheet)
            {
                var sheets = typeof sheet !== 'undefined' ? [sheet] : document.styleSheets;
                for (var i = 0, l = sheets.length; i < l; i++)
                {
                    var sheet = sheets[i];
                    if( !sheet.cssRules )
                    {
                        continue;
                    }
                    for (var j = 0, k = sheet.cssRules.length; j < k; j++)
                    {
                        var rule = sheet.cssRules[j];
                        if (rule.selectorText && rule.selectorText.split(',').indexOf(selector) !== -1)
                        {
                            return rule.style;
                        }
                    }
                }
                return null;
            }

            var orientation = this.scope.orientation;
            var isVertical = this.scope.isVertical = orientation == 'vertical';

            // get the size of the splitter from the pane2 border and its hitzone from split-handler
            var borderStyle = scope.getStyleRule('.split-panes.'+ orientation +' > .split-pane2');
            var border = isVertical? borderStyle['border-left']: borderStyle['border-top'];
            var sizePx = border.split(' ')[0];
            var splitterSize = parseInt(sizePx.substring(0, sizePx.indexOf('px')));


            // adjust handler size
            if (this.scope.size)
            {
                splitterSize = Number(scope.size);
            }

            this.scope.splitterSize = splitterSize;
        }],
        link: {
            pre: function preLink(scope, element, attrs, bgPane)
            {
                function calcSizes(scope, width, height)
                {
                    scope.width = width;
                    scope.height = height;

                    scope.paneSizes = [];
                    var range = scope.isVertical ? width : height;
                    var val = 0;

                    var pos = scope.pos;

                    if (pos == null)
                    {
                        pos = "50%";
                    }


                    if (pos.indexOf('%') != -1)
                    {
                        // handle percent
                        var posStr = pos.substring(0, pos.indexOf('%'));
                        var fraction = Number(posStr) / 100;

                        val = range * fraction | 0;
                        val = val < 0 ? range + val - scope.splitterSize : val;
                    }
                    else
                    {
                        // handle pixels
                        var pixels = parseInt(pos);
                        val = pixels < 0 ? range + pixels - scope.splitterSize: pixels;
                    }

                    if (scope.isVertical)
                    {
                        scope.paneSizes.push([val, height], [width - val, height]);
                        scope.startX = val;
                    }
                    else
                    {
                        scope.paneSizes.push([width, val], [width, height - val]);
                        scope.startY = val;
                    }
                }

                // calculate the width and height of each pane
                if (bgPane)
                {
                    var width = bgPane.scope.paneSize[0];
                    var height = bgPane.scope.paneSize[1];
                    calcSizes(scope, width, height);
                }
                else
                {
                    var bounds = element[0].getBoundingClientRect();
                    var width = bounds.right - bounds.left;
                    var height = bounds.bottom - bounds.top;
                    calcSizes(scope, width, height);
                }
            },
            post: function postLink (scope, element, attrs, bgPane)
            {
                var handler = angular.element('<div class="split-handler"></div>');
                var pane1 = scope.panes[0];
                var pane2 = scope.panes[1];
                var pane1Min = pane1.minSize || 0;
                var pane2Min = pane2.minSize || 0;
                var drag = false;

                pane1.elem.after(handler);


                function resize (ev)
                {
                    if (!drag) return;

                    var bounds = element[0].getBoundingClientRect();
                    var pos = 0;

                    if (scope.isVertical)
                    {
                        var width = bounds.right - bounds.left;
                        pos = ev.clientX - bounds.left;

                        if (pos < pane1Min) pos = pane1Min;
                        if (width - pos < pane2Min) pos = width - pane2Min;

                        handler.css('left', pos + 'px');
                        pane1.elem.css('width', pos + 'px');
                        pane2.elem.css('left', pos + 'px');

                    } else {
                        var height = bounds.bottom - bounds.top;
                        pos = ev.clientY - bounds.top;

                        if (pos < pane1Min) pos = pane1Min;
                        if (height - pos < pane2Min) pos = height - pane2Min;

                        handler.css('top', pos + 'px');
                        pane1.elem.css('height', pos + 'px');
                        pane2.elem.css('top', pos + 'px');
                    }
{'fraction_non_alphanumeric': 0.10462306073126998, 'fraction_numerical': 0.007016449676463709, 'mean_word_length': 0.9495440729483283, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 15, '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': '5061328', 'n_tokens_mistral': 3264, 'n_tokens_neox': 2957, 'n_words': 734}