From f315895a42062409b6f4b1ab57d45d1524cbc69c Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Tue, 18 Mar 2025 07:45:27 +0100 Subject: [PATCH] almost working search in panel --- fm.c | 7 ++++--- function.c | 11 ++++++++--- function.h | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fm.c b/fm.c index 295afd9..f4af40e 100644 --- a/fm.c +++ b/fm.c @@ -200,7 +200,7 @@ int main (int argc, char *argv[]) /* event loop */ int stop = 0; int mode = 0; - char *search[2] = {0}; + char *search[MAXPANELS] = {0}; while (!stop) { int len = 0; elem_t *current = NULL; @@ -238,8 +238,7 @@ int main (int argc, char *argv[]) /* display panel */ if ((mode) && (search[i])) { - int n = (list[i]->nb + windir[i]->nbcols - 1) / windir[i]->nbcols; - jumpto (list[i], n, windir[i]->ysize, search[i], index_x + i, index_y + i, page + i); + jumpto (list[i], windir[i]->nbcols, windir[i]->ysize, search[i], &index_x[i], &index_y[i], &page[i], 0); } displaywindow (windir[i], list[i], page[i], &index_x[i], &index_y[i], &index_f[i], search[i]); @@ -282,8 +281,10 @@ int main (int argc, char *argv[]) helpwindow (help1, (width - strmaxlen (help0, '\n')) / 2, 3 * yoffset); break; case ALT_N: + jumpto (list[panel], windir[panel]->nbcols, windir[panel]->ysize, search[panel], &index_x[panel], &index_y[panel], &page[panel], 1); break; case ALT_P: + jumpto (list[panel], windir[panel]->nbcols, windir[panel]->ysize, search[panel], &index_x[panel], &index_y[panel], &page[panel], -1); break; case ALT_Q: mode = 0; diff --git a/function.c b/function.c index a527d1c..82f7380 100644 --- a/function.c +++ b/function.c @@ -804,10 +804,15 @@ int find (char **lines, int nblines, int skip, char *search) return -1; } -void jumpto (list_t *list, int height, int pageheight, char *search, int *x, int *y, int *page) +void jumpto (list_t *list, int nbcols, int pageheight, char *search, int *x, int *y, int *page, int offset) { - //height: int n = (list[i]->nb + windir[i]->nbcols - 1) / windir[i]->nbcols; - int skip = *x * height + *y; + int height = (list->nb + nbcols - 1) / nbcols; + int skip = *x * height + *y + offset; + if (skip >= list->nb) { + skip = 0; + } else if (skip < 0) { + skip = list->nb - 1; + } char **_list = (char **) calloc (list->nb, sizeof (char *)); CHECKALLOC (_list); int j; diff --git a/function.h b/function.h index 4aad048..eb674a7 100644 --- a/function.h +++ b/function.h @@ -71,7 +71,7 @@ char **splithexalines (char *buffer, int length, int width); int find (char **lines, int nblines, int skip, char *search); -void jumpto (list_t *list, int height, int pageheight, char *search, int *x, int *y, int *page); +void jumpto (list_t *list, int nbcols, int pageheight, char *search, int *x, int *y, int *page, int offset); #endif /* __FUNCTION_H__ */ -- 2.30.2