<commit_before>import QtQuick 1.0

MouseArea {
    id: popup
    // There is no global toplevel so we have to make one
    // We essentially reparent this item to the root item
    Component.onCompleted: {
        var p = parent;
        while (p.parent != undefined)
            p = p.parent
        parent = p;
    }

    anchors.fill: parent  // fill the while app area
    opacity: popupFrameLoader.item.opacity  // let the frame control opacity, so it can set the behavior

    property string behavior: popupFrameLoader.item && popupFrameLoader.item.behavior ? popupFrameLoader.item.behavior : "MacOS"
    property bool desktopBehavior: (behavior == "MacOS" || behavior == "Windows" || behavior == "Linux")
    property int previousCurrentIndex: -1   // set in state transition last in this file

    property alias model: listView.model
    property alias currentIndex: listView.currentIndex

    property Component listItem
    property Component listHighlight
    property Component popupFrame

    function togglePopup() { state = (state == "" ? "hidden" : "") }
    function setCurrentIndex(index) { listView.currentIndex = index; }
    function cancelSelection() { listView.currentIndex = previousCurrentIndex; }
    function closePopup() { state = "hidden" }

    function positionPopup() {
        switch(behavior) {
        case "MacOS":
            var mappedListPos = mapFromItem(choiceList, 0, 0);
            var itemHeight = Math.max(listView.contentHeight/listView.count, 0);
            var currentItemY = Math.max(currentIndex*itemHeight, 0);
            currentItemY += Math.floor(itemHeight/2 - choiceList.height/2);  // correct for choiceLists that are higher than items in the list

            listView.y = mappedListPos.y - currentItemY;
            listView.x = mappedListPos.x;

            listView.width = choiceList.width;
            listView.height = listView.contentHeight    //mm see QTBUG-16037

            if(listView.y < topMargin) {
                var excess = Math.floor(currentItemY - mappedListPos.y);
                listView.y = topMargin;
                listView.height += excess;
                listView.contentY = excess + topMargin;

                if(listView.contentY != excess+topMargin) //mm setting listView.height seems to make it worse
                    print("!!! ChoiceListPopup.qml: listView.contentY should be " + excess+topMargin + " but is " + listView.contentY)
            }

            if(listView.height+listView.contentY > listView.contentHeight) {
                listView.height = listView.contentHeight-listView.contentY;
            }

            if(listView.y+listView.height+bottomMargin > popup.height) {
                listView.height = popup.height-listView.y-bottomMargin;
            }
            break;
        case "Windows":
            var point = popup.mapFromItem(choiceList, 0, choiceList.height);
            listView.y = point.y;
            listView.x = point.x;

            listView.width = choiceList.width;
            listView.height = choiceList.contentHeight;
            listView.width = choiceList.width;
            listView.height = listView.contentHeight    //mm see QTBUG-16037

            if(listView.y < topMargin) {
                var excess = Math.floor(currentItemY - mappedListPos.y);
                listView.y = topMargin;
                listView.height += excess;
                listView.contentY = excess + topMargin;

                if(listView.contentY != excess+topMargin) //mm setting listView.height seems to make it worse
                    print("!!! ChoiceListPopup.qml: listView.contentY should be " + excess+topMargin + " but is " + listView.contentY)
            }

            if(listView.height+listView.contentY > listView.contentHeight) {
                listView.height = listView.contentHeight-listView.contentY;
            }

            if(listView.y+listView.height+bottomMargin > popup.height) {<commit_msg>Hide a warning..<commit_after>import QtQuick 1.0

MouseArea {
    id: popup
    // There is no global toplevel so we have to make one
    // We essentially reparent this item to the root item
    Component.onCompleted: {
        var p = parent;
        while (p.parent != undefined)
            p = p.parent
        parent = p;
    }

    anchors.fill: parent  // fill the while app area
    opacity: popupFrameLoader.item.opacity  // let the frame control opacity, so it can set the behavior

    property string behavior: popupFrameLoader.item && popupFrameLoader.item.behavior ? popupFrameLoader.item.behavior : "MacOS"
    property bool desktopBehavior: (behavior == "MacOS" || behavior == "Windows" || behavior == "Linux")
    property int previousCurrentIndex: -1   // set in state transition last in this file

    property alias model: listView.model
    property alias currentIndex: listView.currentIndex

    property Component listItem
    property Component listHighlight
    property Component popupFrame

    function togglePopup() { state = (state == "" ? "hidden" : "") }
    function setCurrentIndex(index) { listView.currentIndex = index; }
    function cancelSelection() { listView.currentIndex = previousCurrentIndex; }
    function closePopup() { state = "hidden" }

    function positionPopup() {
        switch(behavior) {
        case "MacOS":
            var mappedListPos = mapFromItem(choiceList, 0, 0);
            var itemHeight = Math.max(listView.contentHeight/listView.count, 0);
            var currentItemY = Math.max(currentIndex*itemHeight, 0);
            currentItemY += Math.floor(itemHeight/2 - choiceList.height/2);  // correct for choiceLists that are higher than items in the list

            listView.y = mappedListPos.y - currentItemY;
            listView.x = mappedListPos.x;

            listView.width = choiceList.width;
            listView.height = listView.contentHeight    //mm see QTBUG-16037

            if(listView.y < topMargin) {
                var excess = Math.floor(currentItemY - mappedListPos.y);
                listView.y = topMargin;
                listView.height += excess;
                listView.contentY = excess + topMargin;

                if(listView.contentY != excess+topMargin) //mm setting listView.height seems to make it worse
                    print("!!! ChoiceListPopup.qml: listView.contentY should be " + excess+topMargin + " but is " + listView.contentY)
            }

            if(listView.height+listView.contentY > listView.contentHeight) {
                listView.height = listView.contentHeight-listView.contentY;
            }

            if(listView.y+listView.height+bottomMargin > popup.height) {
                listView.height = popup.height-listView.y-bottomMargin;
            }
            break;
        case "Windows":
            var point = popup.mapFromItem(choiceList, 0, choiceList.height);
            listView.y = point.y;
            listView.x = point.x;

            listView.width = choiceList.width;
            listView.height = choiceList.contentHeight;
            listView.width = choiceList.width;
            listView.height = listView.contentHeight    //mm see QTBUG-16037

            return; // ### fix

            if(listView.y < topMargin) {
                var excess = Math.floor(currentItemY - mappedListPos.y);
                listView.y = topMargin;
                listView.height += excess;
                listView.contentY = excess + topMargin;

                if(listView.contentY != excess+topMargin) //mm setting listView.height seems to make it worse
                    print("!!! ChoiceListPopup.qml: listView.contentY should be " + excess+topMargin + " but is " + listView.contentY)
            }

            if(listView.height+listView.contentY > listView.contentHeight) {
                listView.height = listView.contentHeight-listView.contentY;
            }

            if(listView.y+listView.height+bottomMargin > popup.height) {
{'fraction_non_alphanumeric': 0.09354960392304791, 'fraction_numerical': 0.005029548598013328, 'mean_word_length': 2.207258064516129, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 11, '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': '124543', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2105, 'n_words': 532}