Something went wrong. Try again.
The agentic engineering control plane for the posthuman future
Something went wrong. Try again.
1.9 kB · 62 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263#include "TerminalSearch.h"
QVector<SearchMatch> findAllMatches(const QVector<SearchRow>& rows, const QString& query) { QVector<SearchMatch> matches; const QString needle = query.trimmed(); if (needle.isEmpty()) { return matches; } const qsizetype needleLen = needle.length(); for (const SearchRow& row : rows) { if (row.text.isEmpty()) { continue; } // Case-insensitive plain substring scan. from advances past each hit so // overlapping occurrences are all reported left to right. qsizetype from = 0; while (true) { const qsizetype hit = row.text.indexOf(needle, from, Qt::CaseInsensitive); if (hit < 0) { break; } // UTF-16 offset -> cell column. columnOfChar (when populated) maps // every unit to its grid column, so wide graphemes keep the span // honest; without it the offset IS the column. const int startCol = row.columnOfChar.isEmpty() ? static_cast<int>(hit) : row.columnOfChar[static_cast<int>(hit)]; const qsizetype lastUnit = hit + needleLen - 1; const int endColIncl = row.columnOfChar.isEmpty() ? static_cast<int>(lastUnit) : row.columnOfChar[static_cast<int>(lastUnit)]; matches.append(SearchMatch{.row = row.row, .startCol = startCol, .endCol = endColIncl}); from = hit + 1; } } return matches;}
int wrapStepMatch(int current, int delta, int count) { if (count <= 0) { return -1; } if (current < 0 || current >= count) { // No valid selection: step in lands on the first (next) or last // (previous) match. return delta >= 0 ? 0 : count - 1; } const int next = current + delta; if (next < 0) { return count - 1; } if (next >= count) { return 0; } return next;}