[PATCH] DRY browser.c implementation for to_first_file
Peter Michaux <[email protected]> Tue, 22 Apr 2025 11:36:10 -0700
| Newsgroups | gmane.editors.nano.devel |
|---|---|
| Message-ID | <CAG0y48DnHG5MnA=u4Q++93ikYKfJ-M2kG=CZG=_Dm=W0u5OJLQ@mail.gmail.com> |
The functions to_first_file and to_last_file appear to exist only for the MWHEREISFILE menu. It seems a bit unexpected that these functions are in the MWHEREISFILE menu as they are not text search related functions and they are already in the MBROWSER menu. From a UX perspective, these two functions don't seem to be needed in the MWHEREISFILE menu and it complicates the implementation of prompt.c (line 637). If the two functions are to be in both menus, then it seems like a DRY implementation would be an improvement. A suggested patch is attached. I think there is a better option as these two functions may not be needed in the MWHEREISFILE menu. If the two functions can be removed from the MWHEREISFILE menu, then I could prepare a patch. [This would mean, for example, that there are no `void (*function)(void)` functions in browser.c. At a later date, the browser code could be refactored without the static variables `filelist`, `list_length`, etc at the top of the browser.c. Instead, a struct representing the browser's current state could be passed between functions.] Peter
0001-DRY-browser.c-implementation-for-to_first_file-and-t.patch
(application/octet-stream, 1.7 KB)
From 6b1cb1302333d143ca4df1c116c56943871d5e35 Mon Sep 17 00:00:00 2001 From: Peter Michaux <[email protected]> Date: Tue, 22 Apr 2025 11:12:23 -0700 Subject: [PATCH] DRY browser.c implementation for to_first_file and to_last_file The functions to_first_file and to_last_file exist for the MWHEREISFILE. It seems a bit strange that these functions are in the MWHEREISFILE menu when they are already in the MBROWSER menu. They don't seem to be needed in the MWHEREISFILE and it complicates the implementation of prompt.c. Anyway, they are in both menus and if that will continue to be the situation then it makes sense to DRY out the implementation so there isn't repetition. Signed-off-by: Peter Michaux <[email protected]> --- src/browser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/browser.c b/src/browser.c index 3b2ddb45..52533d0a 100644 --- a/src/browser.c +++ b/src/browser.c @@ -353,13 +353,13 @@ void research_filename(bool forwards) } } -/* Select the first file in the list -- called by ^W^Y. */ +/* Select the first file in the list -- called by M-\ and ^W^Y. */ void to_first_file(void) { selected = 0; } -/* Select the last file in the list -- called by ^W^V. */ +/* Select the last file in the list -- called by M-/ and ^W^V. */ void to_last_file(void) { selected = list_length - 1; @@ -549,9 +549,9 @@ char *browse(char *path) else selected += usable_rows * piles; } else if (function == to_first_file) { - selected = 0; + to_first_file(); } else if (function == to_last_file) { - selected = list_length - 1; + to_last_file(); } else if (function == goto_dir) { /* Ask for the directory to go to. */ if (do_prompt(MGOTODIR, "", NULL, -- 2.39.5 (Apple Git-154)