Commit 1c6955d5 authored by jan.koester's avatar jan.koester
Browse files

test

parent e3375121
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -209,12 +209,32 @@ std::vector<NodeWidgetDescriptor> nodeWidgetCatalog() {
}

bool findNodeWidgetByName(const std::string &name, NodeWidgetDescriptor &out) {
    auto lower = [](std::string value) {
        std::transform(value.begin(), value.end(), value.begin(),
                       [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
        return value;
    };

    const auto catalog = nodeWidgetCatalog();

    // Fast path: exact match.
    auto it = std::find_if(catalog.begin(), catalog.end(), [&](const NodeWidgetDescriptor &d) {
        return name == d.name;
    });
    if (it == catalog.end())

    // Compatibility path: older templates often store capitalized metadata names
    // (e.g. "TextBox") while the script file is lower-case ("textbox.js").
    if (it == catalog.end()) {
        const std::string wanted = lower(name);
        it = std::find_if(catalog.begin(), catalog.end(), [&](const NodeWidgetDescriptor &d) {
            return lower(d.name) == wanted;
        });
    }

    if (it == catalog.end()) {
        return false;
    }

    out = *it;
    return true;
}