From e06d9c9f71d8b00fb442a7ab2a6cc9fd459a2ae6 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Tue, 18 Oct 2016 19:34:11 +0200 Subject: Tiny enhancements and cleanups --- src/sdtui.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sdtui.c b/src/sdtui.c index 54faa7c..00eb163 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -1107,8 +1107,7 @@ static ViewEntry * append_entry (Application *self, guint32 position) { ViewEntry *ve = NULL; - StardictIterator *iterator = stardict_iterator_new - (self->dict, position); + StardictIterator *iterator = stardict_iterator_new (self->dict, position); if (stardict_iterator_is_valid (iterator)) { ve = view_entry_new (iterator); @@ -1184,10 +1183,9 @@ app_scroll_down (Application *self, guint n) break; } + // TODO: try to disallow scrolling past the end ViewEntry *first_entry = g_ptr_array_index (self->entries, 0); - if (self->top_offset < first_entry->definitions_length - 1) - self->top_offset++; - else + if (++self->top_offset >= first_entry->definitions_length) { n_definitions -= first_entry->definitions_length; g_ptr_array_remove_index (self->entries, 0); @@ -1260,7 +1258,8 @@ app_one_entry_down (Application *self) break; } - if (first > LINES - TOP_BAR_CUTOFF - 1) + // FIXME: selection can still get past the end + if (first >= LINES - TOP_BAR_CUTOFF) { self->selected = LINES - TOP_BAR_CUTOFF - 1; app_scroll_down (self, first - (LINES - TOP_BAR_CUTOFF - 1)); @@ -1299,6 +1298,10 @@ app_search_for_entry (Application *self) self->show_help = FALSE; app_reload_view (self); + // Don't let the iterator get past the end of the dictionary + if (!self->entries->len) + (void) app_scroll_up (self, 1); + // If the user wants it centered, just move the view up half a screen; // actually, one third seems to be a better guess if (self->center_search) @@ -1451,13 +1454,11 @@ app_process_user_action (Application *self, UserAction action) case USER_ACTION_GOTO_PAGE_PREVIOUS: app_scroll_up (self, LINES - TOP_BAR_CUTOFF); - // FIXME: selection app_redraw_view (self); RESTORE_CURSOR return TRUE; case USER_ACTION_GOTO_PAGE_NEXT: app_scroll_down (self, LINES - TOP_BAR_CUTOFF); - // FIXME: selection app_redraw_view (self); RESTORE_CURSOR return TRUE; -- cgit v1.2.3-70-g09d2