fix move to next/prev commit in diff view when the log view is not displayed Original analysis and final tweak by yours truly, all the hard work of fixing the program logic by stsp. ok stsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
diff --git a/tog/tog.c b/tog/tog.c
index 71243c7..38cc44f 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1520,12 +1520,29 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
return err;
}
+static void
+select_commit(struct tog_log_view_state *s)
+{
+ struct commit_queue_entry *entry;
+ int ncommits = 0;
+
+ entry = s->first_displayed_entry;
+ while (entry) {
+ if (ncommits == s->selected) {
+ s->selected_entry = entry;
+ break;
+ }
+ entry = TAILQ_NEXT(entry, entry);
+ ncommits++;
+ }
+}
+
static const struct got_error *
draw_commits(struct tog_view *view)
{
const struct got_error *err = NULL;
struct tog_log_view_state *s = &view->state.log;
- struct commit_queue_entry *entry;
+ struct commit_queue_entry *entry = s->selected_entry;
const int limit = view->nlines;
int width;
int ncommits, author_cols = 4;
@@ -1535,17 +1552,6 @@ draw_commits(struct tog_view *view)
struct tog_color *tc;
static const size_t date_display_cols = 12;
- entry = s->first_displayed_entry;
- ncommits = 0;
- while (entry) {
- if (ncommits == s->selected) {
- s->selected_entry = entry;
- break;
- }
- entry = TAILQ_NEXT(entry, entry);
- ncommits++;
- }
-
if (s->selected_entry &&
!(view->searching && view->search_next_done == 0)) {
err = got_object_id_str(&id_str, s->selected_entry->id);
@@ -2361,17 +2367,17 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
s->selected--;
else
log_scroll_up(s, 1);
+ select_commit(s);
break;
case KEY_PPAGE:
case CTRL('b'):
if (s->first_displayed_entry == NULL)
break;
- if (TAILQ_FIRST(&s->commits.head) ==
- s->first_displayed_entry) {
+ if (TAILQ_FIRST(&s->commits.head) == s->first_displayed_entry)
s->selected = 0;
- break;
- }
- log_scroll_up(s, view->nlines - 1);
+ else
+ log_scroll_up(s, view->nlines - 1);
+ select_commit(s);
break;
case 'j':
case KEY_DOWN:
@@ -2380,11 +2386,14 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
if (s->first_displayed_entry == NULL)
break;
if (s->selected < MIN(view->nlines - 2,
- s->commits.ncommits - 1)) {
+ s->commits.ncommits - 1))
s->selected++;
- break;
+ else {
+ err = log_scroll_down(view, 1);
+ if (err)
+ break;
}
- err = log_scroll_down(view, 1);
+ select_commit(s);
break;
case KEY_NPAGE:
case CTRL('f'): {
@@ -2402,7 +2411,7 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
s->selected = MIN(view->nlines - 2,
s->commits.ncommits - 1);
}
- err = NULL;
+ select_commit(s);
break;
}
case KEY_RESIZE:
@@ -2410,6 +2419,7 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
s->selected = view->nlines - 2;
if (s->selected > s->commits.ncommits - 1)
s->selected = s->commits.ncommits - 1;
+ select_commit(s);
if (s->commits.ncommits < view->nlines - 1 &&
!s->thread_args.log_complete) {
s->thread_args.commits_needed += (view->nlines - 1) -
@@ -3598,7 +3608,6 @@ input_diff_view(struct tog_view **new_view, struct tog_view *view, int ch)
const struct got_error *err = NULL;
struct tog_diff_view_state *s = &view->state.diff;
struct tog_log_view_state *ls;
- struct commit_queue_entry *entry;
int i;
switch (ch) {
@@ -3671,16 +3680,12 @@ input_diff_view(struct tog_view **new_view, struct tog_view *view, int ch)
if (s->log_view == NULL)
break;
ls = &s->log_view->state.log;
- entry = TAILQ_PREV(ls->selected_entry,
- commit_queue_head, entry);
- if (entry == NULL)
- break;
err = input_log_view(NULL, s->log_view, KEY_UP);
if (err)
break;
- err = set_selected_commit(s, entry);
+ err = set_selected_commit(s, ls->selected_entry);
if (err)
break;
@@ -3696,21 +3701,11 @@ input_diff_view(struct tog_view **new_view, struct tog_view *view, int ch)
break;
ls = &s->log_view->state.log;
- if (TAILQ_NEXT(ls->selected_entry, entry) == NULL) {
- ls->thread_args.commits_needed++;
- err = trigger_log_thread(s->log_view, 1);
- if (err)
- break;
- }
err = input_log_view(NULL, s->log_view, KEY_DOWN);
if (err)
break;
- entry = TAILQ_NEXT(ls->selected_entry, entry);
- if (entry == NULL)
- break;
-
- err = set_selected_commit(s, entry);
+ err = set_selected_commit(s, ls->selected_entry);
if (err)
break;