diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 8e6b17dbbfd29547d80fa2749d3b3fe629024a81
parent b3e8707662452b1a9d270c1374fd255b736c34cc
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sat, 20 Nov 2021 23:03:13 +0100

Fix diff_days

Diffstat:
Msrc/diary.c | 27+++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/diary.c b/src/diary.c @@ -708,22 +708,21 @@ int main(int argc, char** argv) { int diff_wdays = abs((pad_cx - event.x) / 3); fprintf(stderr, "Diff wdays: %i\n", diff_wdays); - int diff_days; + int diff_days = 0; if (pad_cy > event.y) { - // old position cy is more recent, jump backward by diff_days - diff_days = - (diff_weeks * 7 - diff_wdays); - } else if (pad_cy == event.y) { - fprintf(stderr, "Move within same week\n"); - // move within same week - if (cx > event.x) { - // jump backwards, mouse click was before previous position - diff_days = - diff_wdays; - } else { - diff_days = diff_wdays; - } + // current position cy is more recent, jump backward by diff_days + diff_days -= diff_weeks * 7; + } else { + // new y event is more recent, jump forward by diff_days + diff_days = diff_weeks * 7; + } + + if (cx > event.x) { + // jump backwards, mouse click was before current position + diff_days -= diff_wdays; } else { - // old position cy is before new y event, jump forward by diff_days - diff_days = diff_weeks * 7 + diff_wdays; + // jump forward, mouse click was after current position + diff_days += diff_wdays; } fprintf(stderr, "Diff days: %i\n", diff_days);