Skip to content

Empty Lines not counted within styleInfo #27

@nil-ableton

Description

@nil-ableton

While debugging a styled element, I sometimes look at styleInfo to show the origin of the rule being matched.
I noticed that the line numbers were sometimes off by a few lines, which is confusing.
After reproducing I figured that the line counts were incorrect because they seem to ignore empty lines.
Here is a repro case:
linenumbers-in-styleinfo.css

















WidgetA {
    border-width: 0
}










WidgetA .title {
    fontSize: 24
}

app.qml

import QtQuick 2.3 as QQ
import QtQuick.Layouts 1.2 as QQLayouts

import Aqt.StyleSheets 1.0 as Styles

QQ.Rectangle {
    id: root
    width: 800
    height: 600
    Styles.StyleEngine {
        id: styleEngine
        stylePath: "../css"
        styleName: "linenumbers-in-styleinfo.css"
    }
    QQ.Text {
        id: debugInfoText
        property var debugText
        wrapMode: QQ.Text.WordWrap
        width: 370
        height: contentHeight
        font.family: "Arial"
        font.pointSize: 12
        color: "ivory"
        z: 1000
        readonly property point anchorPoint: {
            if (debugInfoText.debugText) { 
                var input = debugInfoText.debugText;
                return root.mapFromItem(
                    input.originItem, input.x, input.y
                );
            } else {
                return Qt.point(0,0);
            }
        }
        visible: !!debugText || false
        text: (debugText && debugText.text) || ""
        x: anchorPoint.x
        y: anchorPoint.y

        QQ.Rectangle {
            color: "transparent"
            border.width: 2
            readonly property point origin: {
                if (debugInfoText.debugText) {
                    var input = debugInfoText.debugText;
                    return debugInfoText.mapFromItem(input.originItem, 0);
                }
                return Qt.point(0,0);
            }
            x: origin.x
            y: origin.y
            width: debugInfoText.debugText && debugInfoText.debugText.originItem.width
            height: debugInfoText.debugText && debugInfoText.debugText.originItem.height
        }
    }

    QQLayouts.ColumnLayout {
        anchors.fill: parent
        anchors.margins: 8
        WidgetA {
            id: widgetA
            QQLayouts.Layout.fillWidth: true
            QQLayouts.Layout.fillHeight: true
            title: "コードごっこする"

            QQ.MouseArea {
                id: mouseArea1
                anchors.fill: parent
                hoverEnabled: true
                QQ.Binding {
                    when: mouseArea1.containsMouse
                    target: debugInfoText
                    property: 'debugText'
                    value: ({ 
                        text: widgetA.Styles.StyleSet.styleInfo, 
                        originItem: mouseArea1, 
                        x: mouseArea1.mouseX, 
                        y: mouseArea1.mouseY,
                    })
                }
            }
            QQ.Text {
                id: containedTitle
                Styles.StyleSet.name: "title"
                font.pixelSize: Styles.StyleSet.props.number("fontSize") || 12
                text: "TITLE"

                QQ.MouseArea {
                    id: mouseArea2
                    anchors.fill: parent
                    hoverEnabled: true
                    QQ.Binding {
                        when: mouseArea2.containsMouse
                        target: debugInfoText
                        property: 'debugText'
                        value: ({ 
                            text: containedTitle.Styles.StyleSet.styleInfo,
                            originItem: mouseArea2, 
                            x: mouseArea2.mouseX, 
                            y: mouseArea2.mouseY,
                        })
                    }
                }
            }
        }
    }
}

capture

Notice how the .title rule is said to be coming from line 6 when it actually comes from line 31

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions