Skip to content

Commit

Permalink
curses_helper: Fix a mouse-related crash
Browse files Browse the repository at this point in the history
Clicking at locations on the screen that doesn't match a line
in a list view would cause cmu to crash.

Signed-off-by: David Weinehall <[email protected]>
  • Loading branch information
dweineha committed Sep 11, 2023
1 parent e2f7138 commit 247bc8d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions curses_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3205,7 +3205,12 @@ def handle_mouse_events(self, win: curses.window, sorted_list, activatedfun, ext
if bstate == curses.BUTTON1_DOUBLE_CLICKED and selections == True:
# double-clicks on list items
if activatedfun is not None and cypos <= y < min(cheight + cypos, cmaxy) and cxpos <= x < cmaxx:
selected = sorted_list[ypos + cyoffset]
# We want to move the cursor here,
# if "here" is a valid line
try:
selected = sorted_list[ypos + cyoffset]
except IndexError:
return Retval.NOMATCH
self.select(selected)
self.curypos = ypos

Expand Down Expand Up @@ -3235,8 +3240,12 @@ def handle_mouse_events(self, win: curses.window, sorted_list, activatedfun, ext

# If we are clicking on something that is not selected (or if nothing is selected), move here
if selected is None or selected != sorted_list[ypos + cyoffset]:
# We want to move the cursor here
self.selected = sorted_list[ypos + self.yoffset]
# We want to move the cursor here,
# if "here" is a valid line
try:
self.selected = sorted_list[ypos + self.yoffset]
except IndexError:
return Retval.NOMATCH
self.curypos = ypos
else:
# If we click an already selected item we open it
Expand Down

0 comments on commit 247bc8d

Please sign in to comment.