Merge pull request #1155 from aws-lumberyard-dev/LYN4281_ScriptCanvasNodePaletteSearchIgnoreWhitespace

Graph Canvas Node Palette Search Ignore Whitespace
main
Gene Walters 5 years ago committed by GitHub
commit be0d0afc67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<int, int> highlight(regexIndex, m_filter.size());
AZStd::pair<int, int> 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()

Loading…
Cancel
Save