From 90fd676748fd92c356c89fe037379e54e087c1d0 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Fri, 4 Jun 2021 18:19:35 -0700 Subject: [PATCH] update to let regex ingore whitespace instead of removing whitespace by hand in order to preserve the original node name and lets us accurately highlight the matching part of the node name --- .../Model/NodePaletteSortFilterProxyModel.cpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 9e1e0688b4..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,17 +147,17 @@ namespace GraphCanvas return true; } - // Ignore whitespace when filtering node names - QString test = model->data(index).toString().simplified().replace(" ", ""); + + 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 @@ -285,10 +285,19 @@ namespace GraphCanvas void NodePaletteSortFilterProxyModel::SetFilter(const QString& filter) { // Remove whitespace and escape() so every regexp special character is escaped with a backslash - // Removing the whitespace will allow us to find nodes even if the node is written with or without spaces. + // 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(" ", "")); - m_filterRegex = QRegExp(m_filter, Qt::CaseInsensitive); + + 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()