summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-07 22:40:40 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-07 22:40:40 +0300
commit320791c629e988f4634590aadf1bee5ee53d1785 (patch)
tree3333ccc0e5fa160e116757b06e6e0f72d35ff063
parent5e556c4ebbecd8979ee1d7088d98da121971a9ea (diff)
LookupWidget: Improved multi-word matches
All search terms must be found in order, but may have anything between them.
-rw-r--r--src/history.c12
-rw-r--r--src/ui/lookupwidget.c2
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. */
26#include <the_Foundation/file.h> 26#include <the_Foundation/file.h>
27#include <the_Foundation/mutex.h> 27#include <the_Foundation/mutex.h>
28#include <the_Foundation/path.h> 28#include <the_Foundation/path.h>
29#include <the_Foundation/stringset.h>
29 30
30static const size_t maxStack_History_ = 50; /* back/forward navigable items */ 31static const size_t maxStack_History_ = 50; /* back/forward navigable items */
31 32
@@ -255,7 +256,9 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) {
255const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { 256const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) {
256 iStringArray *urls = iClob(new_StringArray()); 257 iStringArray *urls = iClob(new_StringArray());
257 lock_Mutex(d->mtx); 258 lock_Mutex(d->mtx);
258 iConstForEach(Array, i, &d->recent) { 259 iStringSet inserted;
260 init_StringSet(&inserted);
261 iReverseConstForEach(Array, i, &d->recent) {
259 const iRecentUrl *url = i.value; 262 const iRecentUrl *url = i.value;
260 const iGmResponse *resp = url->cachedResponse; 263 const iGmResponse *resp = url->cachedResponse;
261 if (resp && category_GmStatusCode(resp->statusCode) == categorySuccess_GmStatusCode) { 264 if (resp && category_GmStatusCode(resp->statusCode) == categorySuccess_GmStatusCode) {
@@ -274,6 +277,7 @@ const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pat
274 initRange_String(&content, (iRangecc){ m.subject + cap.start, m.subject + cap.end }); 277 initRange_String(&content, (iRangecc){ m.subject + cap.start, m.subject + cap.end });
275 /* This needs cleaning up; highlight the matched word. */ 278 /* This needs cleaning up; highlight the matched word. */
276 replace_Block(&content.chars, '\n', ' '); 279 replace_Block(&content.chars, '\n', ' ');
280 replace_Block(&content.chars, '\r', ' ');
277// insertData_Block(&content.chars, 10, uiTextStrong_ColorEscape, 2); 281// insertData_Block(&content.chars, 10, uiTextStrong_ColorEscape, 2);
278// insertData_Block(&content.chars, size_String(&content) - 10, uiText_ColorEscape, 2); 282// insertData_Block(&content.chars, size_String(&content) - 10, uiText_ColorEscape, 2);
279 format_String( 283 format_String(
@@ -281,11 +285,15 @@ const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pat
281 deinit_String(&content); 285 deinit_String(&content);
282 //appendRange_String(&entry, ); 286 //appendRange_String(&entry, );
283 appendFormat_String(&entry, " url:%s", cstr_String(&url->url)); 287 appendFormat_String(&entry, " url:%s", cstr_String(&url->url));
284 pushBack_StringArray(urls, &entry); 288 if (!contains_StringSet(&inserted, &url->url)) {
289 pushFront_StringArray(urls, &entry);
290 insert_StringSet(&inserted, &url->url);
291 }
285 deinit_String(&entry); 292 deinit_String(&entry);
286 } 293 }
287 } 294 }
288 } 295 }
296 deinit_StringSet(&inserted);
289 unlock_Mutex(d->mtx); 297 unlock_Mutex(d->mtx);
290 return urls; 298 return urls;
291} 299}
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) {
246 iBool isFirst = iTrue; 246 iBool isFirst = iTrue;
247 while (nextSplit_Rangecc(range_String(&d->pendingTerm), " ", &word)) { 247 while (nextSplit_Rangecc(range_String(&d->pendingTerm), " ", &word)) {
248 if (isEmpty_Range(&word)) continue; 248 if (isEmpty_Range(&word)) continue;
249 if (!isFirst) appendChar_String(pattern, '|'); 249 if (!isFirst) appendCStr_String(pattern, ".*");
250 for (const char *ch = word.start; ch != word.end; ch++) { 250 for (const char *ch = word.start; ch != word.end; ch++) {
251 /* Escape regular expression characters. */ 251 /* Escape regular expression characters. */
252 if (isSyntaxChar_RegExp(*ch)) { 252 if (isSyntaxChar_RegExp(*ch)) {