aboutsummaryrefslogtreecommitdiffstats
path: root/src/todo.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-01-18 19:19:18 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-01-18 19:19:18 +0100
commitdf1bc59812c87a006904b3aac0543f71cf5484e1 (patch)
treefdc6560e9e1a34cdf5367747216580d0f5bad437 /src/todo.c
parent25a049951cc955b51c2c30b977ebb6cfa7160054 (diff)
downloadcalcurse-df1bc59812c87a006904b3aac0543f71cf5484e1.tar.gz
calcurse-df1bc59812c87a006904b3aac0543f71cf5484e1.zip
Make automatic selection of todo items smarter
* Automatically focus new todo items after adding them to the list. * Keep selection when an item is moved (e.g. by changing its priority). * Focus the next item in the list when an item is removed. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/todo.c')
-rw-r--r--src/todo.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/todo.c b/src/todo.c
index 6cdd0d5..970991a 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -167,19 +167,26 @@ void todo_flag(struct todo *t)
* Returns the position into the linked list corresponding to the
* given todo item.
*/
-int todo_get_position(struct todo *needle)
+int todo_get_position(struct todo *needle, int skip_completed)
{
llist_item_t *i;
int n = 0;
- LLIST_FOREACH(&todolist, i) {
- if (LLIST_TS_GET_DATA(i) == needle)
- return n;
- n++;
+ if (skip_completed) {
+ LLIST_FIND_FOREACH(&todolist, NULL, todo_is_uncompleted, i) {
+ if (LLIST_TS_GET_DATA(i) == needle)
+ return n;
+ n++;
+ }
+ } else {
+ LLIST_FOREACH(&todolist, i) {
+ if (LLIST_TS_GET_DATA(i) == needle)
+ return n;
+ n++;
+ }
}
- EXIT(_("todo not found"));
- return -1; /* avoid compiler warnings */
+ return -1;
}
/* Attach a note to a todo */