Skip to content
Myr

match: fzf: prioritize matches at word boundary, like fzf

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mark Stosberg · committed by Mark Stosberg · parent 785c444 · Browse files · 4 files+32 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fixes: #695

Diff stats

4 files+32 added−1 removed

  • tests:+3 added−0 removed
  • other:+29 added−1 removed

4 files+32 added−1 removed

modified:test/match-mode-fzf.fish+3 added
23 unmodified lines
24@test "shorter matches should match first" $got = long2526test_fzf_mode "\nbcdef\nabcd\n" cd27@test "matched sub-string is closer to the beginning is sorted first." $got = bcdef2829test_fzf_mode "\nSteam\nMicrosoft Teams\n" tea30@test "matched sub-string at word boundary is sorted first." $got = 'Microsoft Teams'
modified:CHANGELOG.md+3 added-1 removed
58 unmodified lines
59 if not specified at all ([#670][670]).60* Improved scrolling with mouse wheel and touchpad ([#673][673]).61* Incorrect touch coordinates with desktop scaling enabled62 ([#686][686]).63* --match-mode=fzf now prioritizes matching at word boundaries,64 matching fzf's behavior. ([#695][695])6566[658]: https://codeberg.org/dnkl/fuzzel/issues/65867[670]: https://codeberg.org/dnkl/fuzzel/issues/67068[673]: https://codeberg.org/dnkl/fuzzel/issues/67369[686]: https://codeberg.org/dnkl/fuzzel/issues/68670[695]: https://codeberg.org/dnkl/fuzzel/issues/695716972### Security73### Contributors7475 * Mark Stosberg
1046 unmodified lines
modified:match.c+25 added
98 unmodified lines
99};100101static int match_thread(void *_ctx);102103static bool104is_word_boundary(const char32_t *str, size_t pos)105{106 /* Position 0 is always a word boundary */107 if (pos == 0)108 return true;109110 /* Check if character before is a space/separator */111 char32_t prev = str[pos - 1];112 return isc32space(prev);113}114115static char32_t *116match_exact(const char32_t *haystack, size_t haystack_len,117 const char32_t *needle, size_t needle_len)118{
703 unmodified lines
822 else823 return 1;824 }825826 /* Prioritize matches at word boundaries */827 if (a->word_boundary != b->word_boundary) {828 return a->word_boundary ? -1 : 1;829 }830 else if (a->score > b->score)831 return -1;832 else if (a->score < b->score)833 return 1;
509 unmodified lines
1343 free(pos);1344 return;1345 }13461347 /* Check if match starts at word boundary */1348 bool word_boundary = false;1349 if (match_name && pos_count > 0) {1350 /* Check if first match position is at a word boundary in the title */1351 word_boundary = is_word_boundary(app->title_lowercase, pos[0].start);1352 }13531354 struct match m = {1355 .matched_type = app_match_type,1356 .application = app,1357 .pos = pos,1358 .pos_count = pos_count,1359 .score = score,1360 .word_boundary = word_boundary,1361 };13621363 const size_t idx = matches->match_count++;1364
123 unmodified lines
1488 .matched_type = MATCHED_NONE,1489 .application = matches->applications->v[i],1490 .pos = NULL,1491 .pos_count = 0,1492 .word_boundary = false,1493 };1494 }14951496 /* Sort */
250 unmodified lines
modified:match.h+1 added
23 unmodified lines
24 struct application *application;25 struct match_substring *pos;26 size_t pos_count;27 size_t score;28 bool word_boundary; /* True if match starts at word boundary */29};3031struct wayland;32struct matches;
49 unmodified lines