Commit 4939468d authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Fix crash when scrolling in a filter view with no processes. Closes #76.

parent 7f92c589
...@@ -234,7 +234,9 @@ int Panel_size(Panel* this) { ...@@ -234,7 +234,9 @@ int Panel_size(Panel* this) {
void Panel_setSelected(Panel* this, int selected) { void Panel_setSelected(Panel* this, int selected) {
assert (this != NULL); assert (this != NULL);
selected = MAX(0, MIN(Vector_size(this->items) - 1, selected)); selected = MIN(Vector_size(this->items) - 1, selected);
if (selected < 0)
selected = 0;
this->selected = selected; this->selected = selected;
if (Panel_eventHandlerFn(this)) { if (Panel_eventHandlerFn(this)) {
Panel_eventHandler(this, EVENT_SETSELECTED); Panel_eventHandler(this, EVENT_SETSELECTED);
...@@ -260,12 +262,14 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -260,12 +262,14 @@ void Panel_draw(Panel* this, bool focus) {
} }
if (this->selected >= last) { if (this->selected >= last) {
last = MIN(itemCount, this->selected + 1); last = MIN(itemCount, this->selected + 1);
first = MAX(0, last - this->h); first = last - this->h;
this->scrollV = first; this->scrollV = first;
this->needsRedraw = true; this->needsRedraw = true;
} }
assert(first >= 0); if (first < 0)
assert(last <= itemCount); first = 0;
if (last > itemCount)
last = itemCount;
int headerLen = RichString_sizeVal(this->header); int headerLen = RichString_sizeVal(this->header);
if (headerLen > 0) { if (headerLen > 0) {
...@@ -398,6 +402,8 @@ bool Panel_onKey(Panel* this, int key) { ...@@ -398,6 +402,8 @@ bool Panel_onKey(Panel* this, int key) {
case KEY_NPAGE: case KEY_NPAGE:
this->selected += (this->h - 1); this->selected += (this->h - 1);
int size = Vector_size(this->items); int size = Vector_size(this->items);
if (this->selected < 0)
this->selected = 0;
if (this->selected >= size) if (this->selected >= size)
this->selected = size - 1; this->selected = size - 1;
this->scrollV += (this->h - 1); this->scrollV += (this->h - 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment