From 320791c629e988f4634590aadf1bee5ee53d1785 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 7 Sep 2020 22:40:40 +0300 Subject: LookupWidget: Improved multi-word matches All search terms must be found in order, but may have anything between them. --- src/history.c | 12 ++++++++++-- src/ui/lookupwidget.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/history.c b/src/history.c index bd77fe7d..10de5b9a 100644 --- a/src/history.c +++ b/src/history.c @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include +#include static const size_t maxStack_History_ = 50; /* back/forward navigable items */ @@ -255,7 +256,9 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) { const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { iStringArray *urls = iClob(new_StringArray()); lock_Mutex(d->mtx); - iConstForEach(Array, i, &d->recent) { + iStringSet inserted; + init_StringSet(&inserted); + iReverseConstForEach(Array, i, &d->recent) { const iRecentUrl *url = i.value; const iGmResponse *resp = url->cachedResponse; if (resp && category_GmStatusCode(resp->statusCode) == categorySuccess_GmStatusCode) { @@ -274,6 +277,7 @@ const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pat initRange_String(&content, (iRangecc){ m.subject + cap.start, m.subject + cap.end }); /* This needs cleaning up; highlight the matched word. */ replace_Block(&content.chars, '\n', ' '); + replace_Block(&content.chars, '\r', ' '); // insertData_Block(&content.chars, 10, uiTextStrong_ColorEscape, 2); // insertData_Block(&content.chars, size_String(&content) - 10, uiText_ColorEscape, 2); format_String( @@ -281,11 +285,15 @@ const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pat deinit_String(&content); //appendRange_String(&entry, ); appendFormat_String(&entry, " url:%s", cstr_String(&url->url)); - pushBack_StringArray(urls, &entry); + if (!contains_StringSet(&inserted, &url->url)) { + pushFront_StringArray(urls, &entry); + insert_StringSet(&inserted, &url->url); + } deinit_String(&entry); } } } + deinit_StringSet(&inserted); unlock_Mutex(d->mtx); return urls; } diff --git a/src/ui/lookupwidget.c b/src/ui/lookupwidget.c index 9951e406..5fcbaacd 100644 --- a/src/ui/lookupwidget.c +++ b/src/ui/lookupwidget.c @@ -246,7 +246,7 @@ static iThreadResult worker_LookupWidget_(iThread *thread) { iBool isFirst = iTrue; while (nextSplit_Rangecc(range_String(&d->pendingTerm), " ", &word)) { if (isEmpty_Range(&word)) continue; - if (!isFirst) appendChar_String(pattern, '|'); + if (!isFirst) appendCStr_String(pattern, ".*"); for (const char *ch = word.start; ch != word.end; ch++) { /* Escape regular expression characters. */ if (isSyntaxChar_RegExp(*ch)) { -- cgit v1.2.3