Greatly simplifying the searching for the next matching filename.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5182 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
a9647b0508
commit
d5177059e8
|
@ -9,6 +9,8 @@
|
||||||
and rename 'search_last_file' to 'came_full_circle'.
|
and rename 'search_last_file' to 'came_full_circle'.
|
||||||
* src/browser.c (filesearch_init, do_fileresearch): Avoid setting
|
* src/browser.c (filesearch_init, do_fileresearch): Avoid setting
|
||||||
'focusing' when searching only for filenames.
|
'focusing' when searching only for filenames.
|
||||||
|
* src/browser.c (findnextfile, do_filesearch, do_fileresearch):
|
||||||
|
Greatly simplify the searching for the next matching filename.
|
||||||
|
|
||||||
2015-04-05 Benno Schulenberg <bensberg@justemail.net>
|
2015-04-05 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* doc/texinfo/nano.texi: Expand on nano's features, condense the
|
* doc/texinfo/nano.texi: Expand on nano's features, condense the
|
||||||
|
|
|
@ -41,8 +41,6 @@ static int longest = 0;
|
||||||
static size_t selected = 0;
|
static size_t selected = 0;
|
||||||
/* The currently selected filename in the list. This variable
|
/* The currently selected filename in the list. This variable
|
||||||
* is zero-based. */
|
* is zero-based. */
|
||||||
static bool came_full_circle = FALSE;
|
|
||||||
/* Have we reached the starting file again while searching? */
|
|
||||||
|
|
||||||
/* Our main file browser function. path is the tilde-expanded path we
|
/* Our main file browser function. path is the tilde-expanded path we
|
||||||
* start browsing from. */
|
* start browsing from. */
|
||||||
|
@ -765,33 +763,38 @@ int filesearch_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for needle. If no_sameline is TRUE, skip over selected when
|
/* Look for the given needle in the list of files. */
|
||||||
* looking for needle. begin is the location of the filename where we
|
void findnextfile(const char *needle)
|
||||||
* first started searching. The return value specifies whether we found
|
|
||||||
* anything. */
|
|
||||||
bool findnextfile(bool no_sameline, size_t begin, const char *needle)
|
|
||||||
{
|
{
|
||||||
size_t currselected = selected;
|
size_t currselected = selected;
|
||||||
/* The location in the current file list of the match we
|
/* The location in the file list of the filename we're looking at. */
|
||||||
* find. */
|
bool came_full_circle = FALSE;
|
||||||
|
/* Have we reached the starting file again? */
|
||||||
const char *filetail = tail(filelist[currselected]);
|
const char *filetail = tail(filelist[currselected]);
|
||||||
/* The filename we display, minus the path. */
|
/* The filename we display, minus the path. */
|
||||||
const char *rev_start = filetail, *found = NULL;
|
const char *rev_start = filetail, *found = NULL;
|
||||||
|
|
||||||
/* Look for needle in the current filename we're searching. */
|
/* Step through each filename in the list until a match is found or
|
||||||
|
* we've come back to the point where we started. */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
found = strstrwrapper(filetail, needle, rev_start);
|
found = strstrwrapper(filetail, needle, rev_start);
|
||||||
|
|
||||||
/* If we've found a potential match and we're not allowed to find
|
/* If we've found a match and it's not the same filename where
|
||||||
* a match on the same filename we started on and this potential
|
* we started, then we're done. */
|
||||||
* match is that filename, continue searching. */
|
if (found != NULL && currselected != selected)
|
||||||
if (found != NULL && (!no_sameline || currselected != begin))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* If we've found a match and we're back at the beginning, then
|
||||||
|
* it's the only occurrence. */
|
||||||
|
if (found != NULL && came_full_circle) {
|
||||||
|
statusbar(_("This is the only occurrence"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (came_full_circle) {
|
if (came_full_circle) {
|
||||||
/* We've finished processing the filenames, so get out. */
|
/* We're back at the beginning and didn't find anything. */
|
||||||
not_found_msg(needle);
|
not_found_msg(needle);
|
||||||
return FALSE;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move to the next filename in the list. If we've reached the
|
/* Move to the next filename in the list. If we've reached the
|
||||||
|
@ -803,7 +806,7 @@ bool findnextfile(bool no_sameline, size_t begin, const char *needle)
|
||||||
statusbar(_("Search Wrapped"));
|
statusbar(_("Search Wrapped"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currselected == begin)
|
if (currselected == selected)
|
||||||
/* We've reached the original starting file. */
|
/* We've reached the original starting file. */
|
||||||
came_full_circle = TRUE;
|
came_full_circle = TRUE;
|
||||||
|
|
||||||
|
@ -812,10 +815,8 @@ bool findnextfile(bool no_sameline, size_t begin, const char *needle)
|
||||||
rev_start = filetail;
|
rev_start = filetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We've definitely found something. */
|
/* Select the one we've found. */
|
||||||
selected = currselected;
|
selected = currselected;
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Abort the current filename search. Clean up by setting the current
|
/* Abort the current filename search. Clean up by setting the current
|
||||||
|
@ -829,9 +830,6 @@ void filesearch_abort(void)
|
||||||
/* Search for a filename. */
|
/* Search for a filename. */
|
||||||
void do_filesearch(void)
|
void do_filesearch(void)
|
||||||
{
|
{
|
||||||
size_t begin = selected;
|
|
||||||
bool didfind;
|
|
||||||
|
|
||||||
UNSET(CASE_SENSITIVE);
|
UNSET(CASE_SENSITIVE);
|
||||||
UNSET(USE_REGEXP);
|
UNSET(USE_REGEXP);
|
||||||
UNSET(BACKWARDS_SEARCH);
|
UNSET(BACKWARDS_SEARCH);
|
||||||
|
@ -855,19 +853,7 @@ void do_filesearch(void)
|
||||||
update_history(&search_history, answer);
|
update_history(&search_history, answer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
came_full_circle = FALSE;
|
findnextfile(answer);
|
||||||
didfind = findnextfile(FALSE, begin, answer);
|
|
||||||
|
|
||||||
/* Check to see if there's only one occurrence of the string and
|
|
||||||
* we're on it now. */
|
|
||||||
if (selected == begin && didfind) {
|
|
||||||
/* Do the search again, skipping over the current line. We
|
|
||||||
* should only end up back at the same position if the string
|
|
||||||
* isn't found again, in which case it's the only occurrence. */
|
|
||||||
didfind = findnextfile(TRUE, begin, answer);
|
|
||||||
if (selected == begin && !didfind)
|
|
||||||
statusbar(_("This is the only occurrence"));
|
|
||||||
}
|
|
||||||
|
|
||||||
filesearch_abort();
|
filesearch_abort();
|
||||||
}
|
}
|
||||||
|
@ -875,29 +861,13 @@ void do_filesearch(void)
|
||||||
/* Search for the last given filename again without prompting. */
|
/* Search for the last given filename again without prompting. */
|
||||||
void do_fileresearch(void)
|
void do_fileresearch(void)
|
||||||
{
|
{
|
||||||
size_t begin = selected;
|
|
||||||
bool didfind;
|
|
||||||
|
|
||||||
if (last_search == NULL)
|
if (last_search == NULL)
|
||||||
last_search = mallocstrcpy(NULL, "");
|
last_search = mallocstrcpy(NULL, "");
|
||||||
|
|
||||||
if (last_search[0] != '\0') {
|
if (last_search[0] == '\0')
|
||||||
came_full_circle = FALSE;
|
statusbar(_("No current search pattern"));
|
||||||
didfind = findnextfile(FALSE, begin, last_search);
|
else
|
||||||
|
findnextfile(last_search);
|
||||||
/* Check to see if there's only one occurrence of the string and
|
|
||||||
* we're on it now. */
|
|
||||||
if (selected == begin && didfind) {
|
|
||||||
/* Do the search again, skipping over the current line. We
|
|
||||||
* should only end up back at the same position if the
|
|
||||||
* string isn't found again, in which case it's the only
|
|
||||||
* occurrence. */
|
|
||||||
didfind = findnextfile(TRUE, begin, last_search);
|
|
||||||
if (selected == begin && !didfind)
|
|
||||||
statusbar(_("This is the only occurrence"));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
statusbar(_("No current search pattern"));
|
|
||||||
|
|
||||||
filesearch_abort();
|
filesearch_abort();
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ functionptrtype parse_browser_input(int *kbinput);
|
||||||
void browser_refresh(void);
|
void browser_refresh(void);
|
||||||
bool browser_select_filename(const char *needle);
|
bool browser_select_filename(const char *needle);
|
||||||
int filesearch_init(void);
|
int filesearch_init(void);
|
||||||
bool findnextfile(bool no_sameline, size_t begin, const char *needle);
|
void findnextfile(const char *needle);
|
||||||
void filesearch_abort(void);
|
void filesearch_abort(void);
|
||||||
void do_filesearch(void);
|
void do_filesearch(void);
|
||||||
void do_fileresearch(void);
|
void do_fileresearch(void);
|
||||||
|
|
Loading…
Reference in New Issue