From 574bceb005d019d411f73bdd7e811d0bca4643b3 Mon Sep 17 00:00:00 2001 From: Patrick Hallen Date: Sat, 28 Mar 2009 19:03:51 +0100 Subject: [PATCH] conf: Added new "jump-prefix-only" option. Commit b36fbc3ed8b9ceed41 broke the usecase of jumping directly to the first entry which begins with a certain letter. This patch adds a new option, which enables the old behaviour, which searches for the beginning of a string and not for the first occurence. --- src/conf.c | 7 +++++++ src/list_window.c | 32 +++++++++++++++----------------- src/match.c | 26 -------------------------- src/match.h | 10 ---------- src/options.c | 1 + src/options.h | 1 + 6 files changed, 24 insertions(+), 53 deletions(-) diff --git a/src/conf.c b/src/conf.c index 478d468..09fa45f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -74,6 +74,7 @@ #define CONF_VISIBLE_BITRATE "visible-bitrate" #define CONF_WELCOME_SCREEN_LIST "welcome-screen-list" #define CONF_DISPLAY_TIME "display-time" +#define CONF_JUMP_PREFIX_ONLY "jump-prefix-only" static bool str2bool(char *str) @@ -502,6 +503,12 @@ parse_line(char *line) {} #else options.display_time = str2bool(value); +#endif + else if (!strcasecmp(CONF_JUMP_PREFIX_ONLY, name)) +#ifdef NCMPC_MINI + {} +#else + options.jump_prefix_only = str2bool(value); #endif else match_found = false; diff --git a/src/list_window.c b/src/list_window.c index 40f2e14..347c54b 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -414,25 +414,23 @@ list_window_jump(struct list_window *lw, const char *label; while ((label = callback(i,&h,callback_data))) { - if (label && label[0] != '[') + if (label && label[0] == '[') + label++; +#ifndef NCMPC_MINI + if (str && label && + ((options.jump_prefix_only && g_ascii_strncasecmp(label, str, strlen(str)) == 0) || + (!options.jump_prefix_only && match_line(label, str))) ) +#else + if (str && label && g_ascii_strncasecmp(label, str, strlen(str)) == 0) +#endif { - if (str && label && find_occurence(label, str, strlen(str)) == 0) { - lw->selected = i; - if(!lw->range_selection || i > lw->selected_end) - lw->selected_end = i; - if(!lw->range_selection || i < lw->selected_start) - lw->selected_start = i; - return true; - } + lw->selected = i; + if(!lw->range_selection || i > lw->selected_end) + lw->selected_end = i; + if(!lw->range_selection || i < lw->selected_start) + lw->selected_start = i; + return true; } - else if (str && label && find_occurence(label+1, str, strlen(str)) == 0) { - lw->selected = i; - if(!lw->range_selection || i > lw->selected_end) - lw->selected_end = i; - if(!lw->range_selection || i < lw->selected_start) - lw->selected_start = i; - return true; - } i++; } return false; diff --git a/src/match.c b/src/match.c index 313c76e..bd52503 100644 --- a/src/match.c +++ b/src/match.c @@ -50,29 +50,3 @@ match_line(const char *line, const char *needle) return ret; } - -int -find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len) -{ - const int str_orig_len = strlen (str_orig); - int i, j; - - if (str_occur_len > str_orig_len) - return -1; - - for (i = 0; i < str_orig_len; i++) { - if ((i + str_occur_len) > str_orig_len) - return -1; - - for (j = 0; j < str_occur_len; j++) { - if (tolower (str_occur[j]) != tolower (str_orig[i+j])) - break; - - if (j == str_occur_len - 1) - return 0; - } - } - - return -1; -} - diff --git a/src/match.h b/src/match.h index 4362cce..fed7207 100644 --- a/src/match.h +++ b/src/match.h @@ -33,13 +33,6 @@ match_line(const char *line, const char *needle) { return strstr(line, needle) != NULL; } - -static inline int -find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len) -{ - return g_ascii_strncasecmp(str_orig, str_occur, str_occur_len); -} - #else /** @@ -49,9 +42,6 @@ find_occurence(const char *str_orig, const char *str_occur, const int str_occur_ bool match_line(const char *line, const char *needle); -int -find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len); - #endif #endif diff --git a/src/options.c b/src/options.c index dd7ba53..4484054 100644 --- a/src/options.c +++ b/src/options.c @@ -64,6 +64,7 @@ options_t options = { .scroll = DEFAULT_SCROLL, .welcome_screen_list = true, .display_time = true, + .jump_prefix_only = true, #endif }; diff --git a/src/options.h b/src/options.h index dbd5a43..bccd0b2 100644 --- a/src/options.h +++ b/src/options.h @@ -73,6 +73,7 @@ typedef struct { bool visible_bitrate; bool welcome_screen_list; bool display_time; + bool jump_prefix_only; #endif } options_t; -- 2.30.2