xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 27f98e201f66572133419c03612db15d1c4ffd50

Pass initial pos to flist_pos.c:find_{next,prev}()
This makes these functions more reusable by allowing to starting at an
arbitrary position and not just where the cursor currently is.
Author: xaizek
Author date (UTC): 2024-12-18 12:56
Committer name: xaizek
Committer date (UTC): 2024-12-18 12:56
Parent(s): de2e413f375049b9671c9ed15d968ca77e51396f
Signing key: 99DC5E4DB05F6BE2
Tree: 62e0ae9b467cffa3570f6e8b900e4b0a94560767
File Lines added Lines deleted
src/flist_pos.c 12 12
File src/flist_pos.c changed (mode: 100644) (index 9589b9c53..996be165e)
... ... static int get_column_top_pos(const view_t *view);
47 47 static int get_column_bottom_pos(const view_t *view); static int get_column_bottom_pos(const view_t *view);
48 48 static const char * get_last_ext(const char name[]); static const char * get_last_ext(const char name[]);
49 49 static int is_mismatched_entry(const dir_entry_t *entry); static int is_mismatched_entry(const dir_entry_t *entry);
50 static int find_next(const view_t *view, entry_predicate pred);
51 static int find_prev(const view_t *view, entry_predicate pred);
50 static int find_next(const view_t *view, int from, entry_predicate pred);
51 static int find_prev(const view_t *view, int from, entry_predicate pred);
52 52 static int file_can_be_displayed(const char directory[], const char filename[]); static int file_can_be_displayed(const char directory[], const char filename[]);
53 53
54 54 int int
 
... ... fpos_prev_dir_sibling(const view_t *view)
740 740 int int
741 741 fpos_next_dir(const view_t *view) fpos_next_dir(const view_t *view)
742 742 { {
743 return find_next(view, &fentry_is_dir);
743 return find_next(view, view->list_pos, &fentry_is_dir);
744 744 } }
745 745
746 746 int int
747 747 fpos_prev_dir(const view_t *view) fpos_prev_dir(const view_t *view)
748 748 { {
749 return find_prev(view, &fentry_is_dir);
749 return find_prev(view, view->list_pos, &fentry_is_dir);
750 750 } }
751 751
752 752 int int
753 753 fpos_next_selected(const view_t *view) fpos_next_selected(const view_t *view)
754 754 { {
755 return find_next(view, &is_entry_selected);
755 return find_next(view, view->list_pos, &is_entry_selected);
756 756 } }
757 757
758 758 int int
759 759 fpos_prev_selected(const view_t *view) fpos_prev_selected(const view_t *view)
760 760 { {
761 return find_prev(view, &is_entry_selected);
761 return find_prev(view, view->list_pos, &is_entry_selected);
762 762 } }
763 763
764 764 int int
765 765 fpos_next_mismatch(const view_t *view) fpos_next_mismatch(const view_t *view)
766 766 { {
767 767 return (view->custom.type == CV_DIFF) return (view->custom.type == CV_DIFF)
768 ? find_next(view, &is_mismatched_entry)
768 ? find_next(view, view->list_pos, &is_mismatched_entry)
769 769 : view->list_pos; : view->list_pos;
770 770 } }
771 771
 
... ... int
773 773 fpos_prev_mismatch(const view_t *view) fpos_prev_mismatch(const view_t *view)
774 774 { {
775 775 return (view->custom.type == CV_DIFF) return (view->custom.type == CV_DIFF)
776 ? find_prev(view, &is_mismatched_entry)
776 ? find_prev(view, view->list_pos, &is_mismatched_entry)
777 777 : view->list_pos; : view->list_pos;
778 778 } }
779 779
 
... ... is_mismatched_entry(const dir_entry_t *entry)
800 800 /* Finds position of the next entry matching the predicate. Returns new /* Finds position of the next entry matching the predicate. Returns new
801 801 * position which isn't changed if no next directory is found. */ * position which isn't changed if no next directory is found. */
802 802 static int static int
803 find_next(const view_t *view, entry_predicate pred)
803 find_next(const view_t *view, int from, entry_predicate pred)
804 804 { {
805 int pos = view->list_pos;
805 int pos = from;
806 806 while(++pos < view->list_rows) while(++pos < view->list_rows)
807 807 { {
808 808 if(pred(&view->dir_entry[pos])) if(pred(&view->dir_entry[pos]))
 
... ... find_next(const view_t *view, entry_predicate pred)
816 816 /* Finds position of the previous entry matching the predicate. Returns new /* Finds position of the previous entry matching the predicate. Returns new
817 817 * position which isn't changed if no previous directory is found. */ * position which isn't changed if no previous directory is found. */
818 818 static int static int
819 find_prev(const view_t *view, entry_predicate pred)
819 find_prev(const view_t *view, int from, entry_predicate pred)
820 820 { {
821 int pos = view->list_pos;
821 int pos = from;
822 822 while(--pos >= 0) while(--pos >= 0)
823 823 { {
824 824 if(pred(&view->dir_entry[pos])) if(pred(&view->dir_entry[pos]))
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master