diff --git a/Gems/GraphCanvas/Code/StaticLib/GraphCanvas/Widgets/NodePalette/Model/NodePaletteSortFilterProxyModel.cpp b/Gems/GraphCanvas/Code/StaticLib/GraphCanvas/Widgets/NodePalette/Model/NodePaletteSortFilterProxyModel.cpp index ca5e962685..2917642d66 100644 --- a/Gems/GraphCanvas/Code/StaticLib/GraphCanvas/Widgets/NodePalette/Model/NodePaletteSortFilterProxyModel.cpp +++ b/Gems/GraphCanvas/Code/StaticLib/GraphCanvas/Widgets/NodePalette/Model/NodePaletteSortFilterProxyModel.cpp @@ -147,16 +147,17 @@ namespace GraphCanvas return true; } - QString test = model->data(index).toString(); + QString test = model->data(index).toString(); + bool showRow = false; - int regexIndex = test.lastIndexOf(m_filterRegex); + int regexIndex = m_filterRegex.indexIn(test); if (regexIndex >= 0) { showRow = true; - - AZStd::pair highlight(regexIndex, m_filter.size()); + + AZStd::pair highlight(regexIndex, m_filterRegex.matchedLength()); currentItem->SetHighlight(highlight); } else @@ -283,8 +284,20 @@ namespace GraphCanvas void NodePaletteSortFilterProxyModel::SetFilter(const QString& filter) { - m_filter = QRegExp::escape(filter); - m_filterRegex = QRegExp(m_filter, Qt::CaseInsensitive); + // Remove whitespace and escape() so every regexp special character is escaped with a backslash + // Then ignore all whitespace by adding \s* (regex optional whitespace match) in between every other character. + // We use \s* instead of simply removing all whitespace from the filter and node-names in order to preserve the node-name and accurately highlight the matching portion. + // Example: "OnGraphStart" or "On Graph Start" + m_filter = QRegExp::escape(filter.simplified().replace(" ", "")); + + QString regExIgnoreWhitespace(m_filter[0]); + for (int i = 1; i < m_filter.size(); ++i) + { + regExIgnoreWhitespace.append("\\s*"); + regExIgnoreWhitespace.append(m_filter[i]); + } + + m_filterRegex = QRegExp(regExIgnoreWhitespace, Qt::CaseInsensitive); } void NodePaletteSortFilterProxyModel::ClearFilter()