diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-01-11 09:42:37 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-01-11 09:42:37 +0100 |
commit | 19b023b221b03a0e322696be8234170ab90984ec (patch) | |
tree | 0ce99991f275406ebb065c4f844bca9be34cd527 /source | |
parent | 4452b08288c25fa833e22c97b57045ec5888b547 (diff) |
Split sorting option. one for sorting. One to force levenshtein.
Diffstat (limited to 'source')
-rw-r--r-- | source/helper.c | 4 | ||||
-rw-r--r-- | source/view.c | 25 | ||||
-rw-r--r-- | source/xrmoptions.c | 4 |
3 files changed, 16 insertions, 17 deletions
diff --git a/source/helper.c b/source/helper.c index 11073d66..72105352 100644 --- a/source/helper.c +++ b/source/helper.c @@ -656,10 +656,8 @@ char *rofi_expand_path ( const char *input ) /** Return the minimum value of a,b,c */ #define MIN3( a, b, c ) ( ( a ) < ( b ) ? ( ( a ) < ( c ) ? ( a ) : ( c ) ) : ( ( b ) < ( c ) ? ( b ) : ( c ) ) ) -unsigned int levenshtein ( const char *needle, const char *haystack ) +unsigned int levenshtein ( const char *needle, const glong needlelen, const char *haystack, const glong haystacklen ) { - const size_t needlelen = g_utf8_strlen ( needle, -1 ); - const size_t haystacklen = g_utf8_strlen ( haystack, -1 ); unsigned int column[needlelen + 1]; for ( unsigned int y = 0; y <= needlelen; y++ ) { column[y] = y; diff --git a/source/view.c b/source/view.c index 8b60dabc..44b555d9 100644 --- a/source/view.c +++ b/source/view.c @@ -140,7 +140,7 @@ void rofi_view_get_current_monitor ( int *width, int *height ) static char * get_matching_state ( void ) { if ( config.case_sensitive ) { - if ( config.levenshtein_sort ) { + if ( config.sort ) { return "±"; } else { @@ -148,7 +148,7 @@ static char * get_matching_state ( void ) } } else{ - if ( config.levenshtein_sort ) { + if ( config.sort ) { return "+"; } } @@ -545,7 +545,7 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data { char *pattern = NULL; glong plen = 0; - if ( config.matching_method == MM_FUZZY || config.levenshtein_sort ) { + if ( config.sort ) { pattern = mode_preprocess_input ( t->state->sw, t->state->text->text ); plen = g_utf8_strlen ( pattern, -1 ); } @@ -554,16 +554,15 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data // If each token was matched, add it to list. if ( match ) { t->state->line_map[t->start + t->count] = i; - if ( config.matching_method == MM_FUZZY ) { - char *str = mode_get_completion ( t->state->sw, i ); - glong slen = g_utf8_strlen ( str, -1 ); - t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( pattern, plen, str, slen ); - g_free ( str ); - } - else if ( config.levenshtein_sort ) { + if ( config.sort ) { // This is inefficient, need to fix it. char * str = mode_get_completion ( t->state->sw, i ); - t->state->distance[i] = levenshtein ( pattern, str ); + glong slen = g_utf8_strlen ( str, -1 ); + if ( config.levenshtein_sort || config.matching_method != MM_FUZZY ) { + t->state->distance[i] = levenshtein ( pattern, plen, str, slen ); + } else { + t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( pattern, plen, str, slen ); + } g_free ( str ); } t->count++; @@ -1034,7 +1033,7 @@ static void rofi_view_refilter ( RofiViewState *state ) } j += states[i].count; } - if ( config.matching_method == MM_FUZZY || config.levenshtein_sort ) { + if ( config.sort ) { g_qsort_with_data ( state->line_map, j, sizeof ( int ), lev_sort, state->distance ); } @@ -1101,7 +1100,7 @@ gboolean rofi_view_trigger_action ( RofiViewState *state, KeyBindingAction actio menu_capture_screenshot ( ); break; case TOGGLE_SORT: - config.levenshtein_sort = !config.levenshtein_sort; + config.sort = !config.sort; state->refilter = TRUE; textbox_text ( state->case_indicator, get_matching_state () ); break; diff --git a/source/xrmoptions.c b/source/xrmoptions.c index eff1644e..85f829c7 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -137,8 +137,10 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL, "Disable history in run/ssh", CONFIG_DEFAULT }, + { xrm_Boolean, "sort", { .num = &config.sort }, NULL, + "Use sorting", CONFIG_DEFAULT }, { xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL, - "Use levenshtein sorting", CONFIG_DEFAULT }, + "Use levenshtein sorting also for fuzzy matching", CONFIG_DEFAULT }, { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, "Set case-sensitivity", CONFIG_DEFAULT }, { xrm_Boolean, "cycle", { .num = &config.cycle }, NULL, |