[gnome-builder] completion: fix page up/down when not at boundaries
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] completion: fix page up/down when not at boundaries
- Date: Thu, 14 Jun 2018 20:25:42 +0000 (UTC)
commit 81308a39eebd67f9e6901be86004a2581dbe21df
Author: Christian Hergert <chergert redhat com>
Date: Thu Jun 14 13:25:02 2018 -0700
completion: fix page up/down when not at boundaries
src/libide/completion/ide-completion-list-box.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/completion/ide-completion-list-box.c b/src/libide/completion/ide-completion-list-box.c
index aa2e379ec..0559c342d 100644
--- a/src/libide/completion/ide-completion-list-box.c
+++ b/src/libide/completion/ide-completion-list-box.c
@@ -57,9 +57,11 @@ struct _IdeCompletionListBox
guint n_rows;
/*
- * The currently selected index within the result set.
+ * The currently selected index within the result set. Signed to
+ * ensure our math in various places allows going negative to catch
+ * lower edge.
*/
- guint selected;
+ gint selected;
/*
* This is set whenever we make a change that requires updating the
@@ -825,7 +827,7 @@ ide_completion_list_box_move_cursor (IdeCompletionListBox *self,
GtkMovementStep step,
gint direction)
{
- guint n_items;
+ gint n_items;
gint offset;
g_return_if_fail (IDE_IS_COMPLETION_LIST_BOX (self));
@@ -836,6 +838,10 @@ ide_completion_list_box_move_cursor (IdeCompletionListBox *self,
if (!(n_items = g_list_model_get_n_items (G_LIST_MODEL (self->context))))
return;
+ /* n_items is signed so that we can do negative comparison */
+ if (n_items < 0)
+ return;
+
if (step == GTK_MOVEMENT_BUFFER_ENDS)
{
if (direction > 0)
@@ -863,9 +869,9 @@ ide_completion_list_box_move_cursor (IdeCompletionListBox *self,
if (step == GTK_MOVEMENT_PAGES)
direction *= self->n_rows;
- if (((gint)self->selected + direction) > n_items)
+ if ((self->selected + direction) > n_items)
self->selected = n_items - 1;
- else if (((gint)self->selected + direction) < 0)
+ else if ((self->selected + direction) < 0)
self->selected = 0;
else
self->selected += direction;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]