summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--smenu.13
-rw-r--r--smenu.c52
-rw-r--r--tests/search/t0021.good10
-rw-r--r--tests/search/t0022.good10
-rw-r--r--tests/search/t0023.good4
-rw-r--r--tests/search/t0024.good4
-rw-r--r--tests/search/t0026.good2
-rw-r--r--tests/search/t0027.good4
8 files changed, 54 insertions, 35 deletions
diff --git a/smenu.1 b/smenu.1
index 4cd3b94..598c64b 100644
--- a/smenu.1
+++ b/smenu.1
@@ -206,6 +206,9 @@ in a word, but need not be consecutive.
The case is also ignored.
+Note that spaces and tabs at the beginning and end of words are ignored
+when searching for substrings or fuzzy strings.
+
The cursor is placed, if possible, on the first matching word having the
minimum number of gaps between the first and last matching character,
see the difference between the actions of the \fBs\fP/\fBS\fP and
diff --git a/smenu.c b/smenu.c
index ff6565f..0c62666 100644
--- a/smenu.c
+++ b/smenu.c
@@ -932,7 +932,7 @@ update_bitmaps(search_mode_t mode, search_data_t * data,
/* following algorithm */
/* .len holds the original length in bytes of the word */
/* """""""""""""""""""""""""""""""""""""""""""""""""""" */
- str_orig[word_a[n].len] = '\0';
+ rtrim(str_orig, " \t", 0);
bm_len = (word_a[n].mb - daccess.flength) / CHAR_BIT + 1;
bm = word_a[n].bitmap;
@@ -1025,24 +1025,32 @@ update_bitmaps(search_mode_t mode, search_data_t * data,
free(str);
- /* We know that the first glyph is part of the pattern, so */
- /* highlight it if it is not and unhighlight the next occurrence */
- /* that must be here because this word has already been filtered */
- /* by select_starting_pattern() */
- /* """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
+ /* We know that the first non blank glyph is part of the pattern, */
+ /* so highlight it if it is not and unhighlight the next occurrence */
+ /* that must be here because this word has already been filtered */
+ /* by select_starting_pattern(). */
+ /* """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
if (affinity == START_AFFINITY)
{
char *ptr1, *ptr2;
- long i = 1;
+ long i;
long utf8_len;
- first_glyph = utf8_strprefix(first_glyph, word_a[n].str, 1,
+ /* Skip leading spaces and tabs. */
+ /* """"""""""""""""""""""""""""" */
+ for (i = 0; i < word_a[n].mb; i++)
+ if (!isblank(*(word_a[n].str + daccess.flength + i)))
+ break;
+
+ first_glyph = utf8_strprefix(first_glyph, word_a[n].str + i, 1,
&utf8_len);
- if (!BIT_ISSET(word_a[n].bitmap, 0))
+ if (!BIT_ISSET(word_a[n].bitmap, i))
{
- BIT_ON(word_a[n].bitmap, 0);
- ptr1 = word_a[n].str;
+ BIT_ON(word_a[n].bitmap, i);
+
+ ptr1 = word_a[n].str + i;
+ i++;
while ((ptr2 = utf8_next(ptr1)) != NULL)
{
if (memcmp(ptr2, first_glyph, utf8_len) == 0)
@@ -3853,7 +3861,7 @@ select_ending_matches(win_t * win, term_t * term, search_data_t * search_data,
nb = 0;
while ((ptr = utf8_prev(str, ptr)) != NULL && isblank(*ptr))
- if (ptr - str + 1 > len)
+ if (ptr - str > 0)
nb++;
else
break;
@@ -3937,6 +3945,7 @@ select_starting_matches(win_t * win, term_t * term, search_data_t * search_data,
long i;
long j = 0;
long index;
+ long nb;
long * tmp;
long pos;
char * first_glyph;
@@ -3950,15 +3959,21 @@ select_starting_matches(win_t * win, term_t * term, search_data_t * search_data,
for (i = 0; i < matches_count; i++)
{
index = matching_words_a[i];
- if (BIT_ISSET(word_a[index].bitmap, 0))
+
+ for (nb = 0; nb < word_a[index].mb; nb++)
+ if (!isblank(*(word_a[index].str + daccess.flength + nb)))
+ break;
+
+ if (BIT_ISSET(word_a[index].bitmap, nb))
alt_matching_words_a[j++] = index;
else
{
+
if (search_mode == FUZZY)
{
first_glyph = utf8_strprefix(first_glyph,
- word_a[index].str + daccess.flength, 1,
- &pos);
+ word_a[index].str + nb + daccess.flength,
+ 1, &pos);
utf8_len = pos;
/* in fuzzy search mode we only look the first glyph */
@@ -3967,18 +3982,19 @@ select_starting_matches(win_t * win, term_t * term, search_data_t * search_data,
alt_matching_words_a[j++] = index;
else
memset(word_a[index].bitmap, '\0',
- (word_a[index].mb - daccess.flength) / CHAR_BIT + 1);
+ (word_a[index].mb + nb - daccess.flength) / CHAR_BIT + 1);
}
else
{
/* in not fuzzy search mode use all the pattern */
/* """""""""""""""""""""""""""""""""""""""""""" */
- if (memcmp(search_data->buf, word_a[index].str, search_data->len)
+ if (memcmp(search_data->buf, word_a[index].str + nb,
+ search_data->len - nb)
== 0)
alt_matching_words_a[j++] = index;
else
memset(word_a[index].bitmap, '\0',
- (word_a[index].mb - daccess.flength) / CHAR_BIT + 1);
+ (word_a[index].mb + nb - daccess.flength) / CHAR_BIT + 1);
}
}
}
diff --git a/tests/search/t0021.good b/tests/search/t0021.good
index 5ac53da..9616170 100644
--- a/tests/search/t0021.good
+++ b/tests/search/t0021.good
@@ -1,11 +1,11 @@
$ OUT=$(smenu -n 18 t0021.in)
c b bcac cabab baac c aaa ab a ab bcaa a bb b b ba c aa cb
-24:07 25:07 26:07 27:07 28:0723 29:0723 47:23 51:23 64:23 69:23
+10:07 11:07 12:07 13:0723 14:0723 15:07 28:23 29:23 34:23 35:23 47:23 51:23 64:23 69:23
aaaab aa ba b ab aaab cbbcaca babb cabbcaaca b cba babbbbbc aababc b a
-24:23 25:23 36:23 38:23
+15:23 16:23 24:23 25:23 36:23 38:23
bcabcccc ca ba aca a a ab b aac bb c c a a b a a ba acb cabaabcca b
-34:23 38:23
+25:23 26:23 34:23 38:23
ca a b aa cbccca a a cb a bb bbbac bbc c cc c bacb bcacabaa ac
19:23 23:23
b babaa a a cbacac a a aac c a aaaca bb a caa cba b b abcbb c
@@ -17,13 +17,13 @@ ca c aaa c cca a bb b ac c b c ca b babbc cc a cbab
baaa cc a baabbcac a b bbc bc bcbcac bba bc b a b cbb cbbc b acba a
50:23 52:23
a a caabbbbb c ba bcb ca cbccac abb aba cc bbb ba cbc cab b cbaab
-7:23 12:23 36:23 38:23 42:23 50:23 60:23 63:23
+7:23 12:23 36:23 38:23 42:23 50:23 60:23 63:23 68:23 69:23
c b cbb
$
$ echo ":$OUT:"
-:aaa ab:
+:cabab:
$ exit 0
diff --git a/tests/search/t0022.good b/tests/search/t0022.good
index 10705e9..3b88aeb 100644
--- a/tests/search/t0022.good
+++ b/tests/search/t0022.good
@@ -1,23 +1,23 @@
$ OUT=$(smenu -n 18 t0022.in)
c b bcac cabab baac c aaa ab a ab bcaa a bb b b ba c aa cb
-24:0723 25:07 26:07 27:07 28:07 29:0723 63:23 69:23
+24:0723 25:07 26:07 27:07 28:07 29:0723 32:23 35:23 63:23 69:23
aaaab aa ba b ab aaab cbbcaca babb cabbcaaca b cba babbbbbc aababc b a
-15:23 16:23 67:23 69:23
+1:23 5:23 15:23 16:23 22:23 25:23 67:23 69:23
bcabcccc ca ba aca a a ab b aac bb c c a a b a a ba acb cabaabcca b
23:23 26:23 33:23 37:23 54:23 56:23 60:23 62:23
ca a b aa cbccca a a cb a bb bbbac bbc c cc c bacb bcacabaa ac
19:23 23:23
b babaa a a cbacac a a aac c a aaaca bb a caa cba b b abcbb c
-66:23 67:23
+37:23 45:23 66:23 67:23
babc c a c b b b ccca b ab ab ba cacc ba bcc cacbb cbba ca
27:23 28:23 30:23 31:23
ca c aaa c cca a bb b ac c b c ca b babbc cc a cbab
baaa cc a baabbcac a b bbc bc bcbcac bba bc b a b cbb cbbc b acba a
-69:23 71:23
+50:23 52:23 69:23 71:23
a a caabbbbb c ba bcb ca cbccac abb aba cc bbb ba cbc cab b cbaab
-40:23 41:23
+36:23 37:23 40:23 41:23
c b cbb
$
diff --git a/tests/search/t0023.good b/tests/search/t0023.good
index 3e3174f..ac03c4a 100644
--- a/tests/search/t0023.good
+++ b/tests/search/t0023.good
@@ -11,11 +11,11 @@ $ OUT=$(smenu -k -n 18 -T \| t0023.in)
àùù€ç €€çç€ é éù退 €ùé çéé€ù é à€à ùù é àé€ç€ ààçà éàçùç ç€ùç€ € àé
18:04 19:04 20:0423 21:04 22:0423 48:04 49:0423 50:04 51:04 52:0423
éàà €çéé€ ù€€ùà ç €ù€ éç€
-6:04 7:04 8:04 9:0423 10:0423
+6:04 7:04 8:04 9:0423 10:0423 24:04 25:0423 26:04 27:0423 28:04
$
$ echo ":$OUT:"
-:éç退|ùé à€|€é à€|ùù退|€ éù€|éù退|àé€ç€|€çéé€:
+:éç退|ùé à€|€é à€|ùù退|€ éù€|éù退|àé€ç€|€çéé€| éç€ :
$ exit 0
diff --git a/tests/search/t0024.good b/tests/search/t0024.good
index 59c509d..6aea485 100644
--- a/tests/search/t0024.good
+++ b/tests/search/t0024.good
@@ -11,11 +11,11 @@ $ OUT=$(smenu -k -n 18 -T \| t0024.in)
àùù€ç €€çç€ é éù退 €ùé çéé€ù é à€à ùù é àé€ç€ ààçà éàçùç ç€ùç€ € àé
18:0423 19:04 20:04 21:0423 22:04 36:0423 37:04 38:04 39:0423 40:04
éàà €çéé€ ù€€ùà ç €ù€ éç€
-
+24:04 25:0423 26:04 27:0423 28:04
$
$ echo ":$OUT:"
-:éùé€ù|éç退|é€ùàà|éà€ùé|éù退|é à€à:
+:éùé€ù|éç退|é€ùàà|éà€ùé|éù退|é à€à| éç€ :
$ exit 0
diff --git a/tests/search/t0026.good b/tests/search/t0026.good
index 5c1751a..3013b5e 100644
--- a/tests/search/t0026.good
+++ b/tests/search/t0026.good
@@ -1,7 +1,7 @@
$ OUT=$(smenu -n 0 -N -- t0026.in)
1) ab 2) ababab 3) abxab 4) abab 5) abab 6) abab
-0:01 1:01 2:01 4:0723 5:0723 7:01 8:01 9:01 15:23 16:23 18:01 19:01 20:01 25:23 26:23 28:01 29:01 30:01 35:23 36:23 38:01 39:01 40:01 48:01 49:01 50:01
+0:01 1:01 2:01 4:0723 5:0723 7:01 8:01 9:01 15:23 16:23 18:01 19:01 20:01 25:23 26:23 28:01 29:01 30:01 35:23 36:23 38:01 39:01 40:01 44:23 45:23 48:01 49:01 50:01 55:23 56:23
$
$ echo ":$OUT:"
diff --git a/tests/search/t0027.good b/tests/search/t0027.good
index 5b0621f..6ee632e 100644
--- a/tests/search/t0027.good
+++ b/tests/search/t0027.good
@@ -9,9 +9,9 @@ $ OUT=$(smenu -n 0 -N -c t0027.in)
4) abab
0:01 1:01 2:01 7:23 8:23
5) abab
-0:01 1:01 2:01
+0:01 1:01 2:01 6:23 7:23
6) abab
-0:01 1:01 2:01
+0:01 1:01 2:01 7:23 8:23
$
$ echo ":$OUT:"