Skip to content

Commit d17a5e0

Browse files
committed
Revert "Feat: fuzzy matching flag -z"
This reverts commit fafc8eb.
1 parent 794c483 commit d17a5e0

File tree

7 files changed

+6
-96
lines changed

7 files changed

+6
-96
lines changed

client/common/common.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ usage(FILE *out, const char *name)
172172
" -h, --help display this help and exit.\n"
173173
" -v, --version display version.\n"
174174
" -i, --ignorecase match items case insensitively.\n"
175-
" -z, --fuzzy enable fuzzy matching.\n"
176175
" -F, --filter filter entries for a given string before showing the menu.\n"
177176
" -w, --wrap wraps cursor selection.\n"
178177
" -l, --list list items vertically down or up with the given number of lines(number of lines down/up). (down (default), up)\n"
@@ -273,7 +272,6 @@ do_getopt(struct client *client, int *argc, char **argv[])
273272
{ "version", no_argument, 0, 'v' },
274273

275274
{ "ignorecase", no_argument, 0, 'i' },
276-
{ "fuzzy", no_argument, 0, 'z' },
277275
{ "filter", required_argument, 0, 'F' },
278276
{ "wrap", no_argument, 0, 'w' },
279277
{ "list", required_argument, 0, 'l' },
@@ -342,7 +340,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
342340
for (optind = 0;;) {
343341
int32_t opt;
344342

345-
if ((opt = getopt_long(*argc, *argv, "hvizwcl:I:p:P:I:x:bfF:m:H:M:W:B:R:nsCTK", opts, NULL)) < 0)
343+
if ((opt = getopt_long(*argc, *argv, "hviwcl:I:p:P:I:x:bfF:m:H:M:W:B:R:nsCTK", opts, NULL)) < 0)
346344
break;
347345

348346
switch (opt) {
@@ -355,9 +353,6 @@ do_getopt(struct client *client, int *argc, char **argv[])
355353
case 'i':
356354
client->filter_mode = BM_FILTER_MODE_DMENU_CASE_INSENSITIVE;
357355
break;
358-
case 'z':
359-
client->fuzzy = true;
360-
break;
361356
case 'F':
362357
client->initial_filter = optarg;
363358
break;
@@ -599,8 +594,6 @@ menu_with_options(struct client *client)
599594
bm_menu_set_border_size(menu, client->border_size);
600595
bm_menu_set_border_radius(menu, client->border_radius);
601596
bm_menu_set_key_binding(menu, client->key_binding);
602-
bm_menu_set_fuzzy_mode(menu, client->fuzzy);
603-
604597

605598
if (client->center) {
606599
bm_menu_set_align(menu, BM_ALIGN_CENTER);

client/common/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct client {
4646
enum bm_password_mode password;
4747
enum bm_key_binding key_binding;
4848
char *monitor_name;
49-
bool fuzzy;
5049
};
5150

5251
char* cstrcopy(const char *str, size_t size);

lib/bemenu.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,6 @@ BM_PUBLIC enum bm_password_mode bm_menu_get_password(struct bm_menu *menu);
934934
*/
935935
BM_PUBLIC void bm_menu_set_key_binding(struct bm_menu *menu, enum bm_key_binding);
936936

937-
/**
938-
* Specify whether fuzzy matching should be used.
939-
*
940-
* @param menu bm_menu instance to set the fuzzy mode on.
941-
* @param fuzzy true to enable fuzzy matching.
942-
*/
943-
BM_PUBLIC void bm_menu_set_fuzzy_mode(struct bm_menu *menu, bool fuzzy);
944-
945937

946938
/** @} Properties */
947939

lib/filter.c

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,17 @@ tokenize(struct bm_menu *menu, char ***out_tokv, uint32_t *out_tokc)
7979
return NULL;
8080
}
8181

82-
struct fuzzy_match {
83-
struct bm_item *item;
84-
int distance;
85-
};
86-
87-
static int fuzzy_match_comparator(const void *a, const void *b) {
88-
const struct fuzzy_match *fa = (const struct fuzzy_match *)a;
89-
const struct fuzzy_match *fb = (const struct fuzzy_match *)b;
90-
91-
return fa->distance - fb->distance;
92-
}
93-
94-
9582
/**
96-
* Dmenu filterer that accepts substring function or fuzzy match.
83+
* Dmenu filterer that accepts substring function.
9784
*
9885
* @param menu bm_menu instance to filter.
9986
* @param addition This will be 1, if filter is same as previous filter with something appended.
10087
* @param fstrstr Substring function used to match items.
101-
* @param fstrncmp String comparison function for exact matches.
10288
* @param out_nmemb uint32_t reference to filtered items count.
103-
* @param fuzzy Boolean flag to toggle fuzzy matching.
10489
* @return Pointer to array of bm_item pointers.
10590
*/
10691
static struct bm_item**
107-
filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const char *a, const char *b), int (*fstrncmp)(const char *a, const char *b, size_t len), uint32_t *out_nmemb, bool fuzzy)
92+
filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const char *a, const char *b), int (*fstrncmp)(const char *a, const char *b, size_t len), uint32_t *out_nmemb)
10893
{
10994
assert(menu && fstrstr && fstrncmp && out_nmemb);
11095
*out_nmemb = 0;
@@ -129,48 +114,13 @@ filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const cha
129114
goto fail;
130115

131116
const char *filter = menu->filter ? menu->filter : "";
132-
if (strlen(filter) == 0) {
133-
goto fail;
134-
}
135117
size_t len = (tokc ? strlen(tokv[0]) : 0);
136118
uint32_t i, f, e;
137-
f = e = 0;
138-
139-
struct fuzzy_match *fuzzy_matches = NULL;
140-
141-
int fuzzy_match_count = 0;
142-
143-
if (fuzzy && !(fuzzy_matches = calloc(count, sizeof(*fuzzy_matches))))
144-
goto fail;
145-
146-
for (i = 0; i < count; ++i) {
119+
for (e = f = i = 0; i < count; ++i) {
147120
struct bm_item *item = items[i];
148121
if (!item->text && tokc != 0)
149122
continue;
150123

151-
if (fuzzy && tokc && item->text) {
152-
const char *text = item->text;
153-
int sidx = -1, eidx = -1, pidx = 0, text_len = strlen(text), distance = 0;
154-
for (int j = 0; j < text_len && text[j]; ++j) {
155-
if (!fstrncmp(&text[j], &filter[pidx], 1)) {
156-
if (sidx == -1)
157-
sidx = j;
158-
pidx++;
159-
if (pidx == strlen(filter)) {
160-
eidx = j;
161-
break;
162-
}
163-
}
164-
}
165-
if (eidx != -1) {
166-
distance = eidx - sidx + (text_len - eidx + sidx) / 3;
167-
fuzzy_matches[fuzzy_match_count++] = (struct fuzzy_match){ item, distance };
168-
continue;
169-
}
170-
}
171-
172-
if (fuzzy) continue;
173-
174124
if (tokc && item->text) {
175125
uint32_t t;
176126
for (t = 0; t < tokc && fstrstr(item->text, tokv[t]); ++t);
@@ -192,23 +142,12 @@ filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const cha
192142
f++; /* where do all matches end */
193143
}
194144

195-
if (fuzzy && fuzzy_match_count > 0) {
196-
qsort(fuzzy_matches, fuzzy_match_count, sizeof(struct fuzzy_match), fuzzy_match_comparator);
197-
198-
for (int j = 0; j < fuzzy_match_count; ++j) {
199-
filtered[f++] = fuzzy_matches[j].item;
200-
}
201-
202-
free(fuzzy_matches);
203-
}
204-
205145
free(buffer);
206146
free(tokv);
207147
return shrink_list(&filtered, menu->items.count, (*out_nmemb = f));
208148

209149
fail:
210150
free(filtered);
211-
free(fuzzy_matches);
212151
free(buffer);
213152
return NULL;
214153
}
@@ -224,7 +163,7 @@ filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const cha
224163
struct bm_item**
225164
bm_filter_dmenu(struct bm_menu *menu, bool addition, uint32_t *out_nmemb)
226165
{
227-
return filter_dmenu_fun(menu, addition, strstr, strncmp, out_nmemb, menu->fuzzy);
166+
return filter_dmenu_fun(menu, addition, strstr, strncmp, out_nmemb);
228167
}
229168

230169
/**
@@ -238,7 +177,7 @@ bm_filter_dmenu(struct bm_menu *menu, bool addition, uint32_t *out_nmemb)
238177
struct bm_item**
239178
bm_filter_dmenu_case_insensitive(struct bm_menu *menu, bool addition, uint32_t *out_nmemb)
240179
{
241-
return filter_dmenu_fun(menu, addition, bm_strupstr, bm_strnupcmp, out_nmemb, menu->fuzzy);
180+
return filter_dmenu_fun(menu, addition, bm_strupstr, bm_strnupcmp, out_nmemb);
242181
}
243182

244183
/* vim: set ts=8 sw=4 tw=0 :*/

lib/internal.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,6 @@ struct bm_menu {
457457
*/
458458
char vim_mode;
459459
uint32_t vim_last_key;
460-
461-
/**
462-
* Should fuzzy matching be used?
463-
*/
464-
bool fuzzy;
465460
};
466461

467462
/* library.c */

lib/menu.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,11 +779,6 @@ bm_menu_set_key_binding(struct bm_menu *menu, enum bm_key_binding key_binding){
779779
menu->key_binding = key_binding;
780780
}
781781

782-
void
783-
bm_menu_set_fuzzy_mode(struct bm_menu *menu, bool fuzzy){
784-
menu->fuzzy = fuzzy;
785-
}
786-
787782
struct bm_item**
788783
bm_menu_get_selected_items(const struct bm_menu *menu, uint32_t *out_nmemb)
789784
{

man/bemenu.1.scd.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ list of executables under PATH and the selected items are executed.
4545
*-i, --ignorecase*
4646
Filter items case-insensitively.
4747

48-
*-z, --fuzzy*
49-
Filter items fuzzily.
50-
5148
*-K, --no-keyboard*
5249
Disable all keyboard events.
5350

0 commit comments

Comments
 (0)