Skip to content

Commit 96dc167

Browse files
Improved the mouse click handler for the RadioList (accept mouse clicks on the text itself).
1 parent d886993 commit 96dc167

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

prompt_toolkit/widgets/base.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,8 @@ def _(event):
628628
def _get_text_fragments(self):
629629
def mouse_handler(mouse_event: MouseEvent):
630630
"""
631-
Sets the _selected_index and current_value based on the user mouse
632-
click. The function uses the moused position y to get the position
633-
of the current list item clicked.
634-
:param mouse_event:
635-
Mouse event containing position clicked
631+
Set `_selected_index` and `current_value` according to the y
632+
position of the mouse click event.
636633
"""
637634
if mouse_event.event_type == MouseEventType.MOUSE_UP:
638635
self._selected_index = mouse_event.position.y
@@ -655,14 +652,18 @@ def mouse_handler(mouse_event: MouseEvent):
655652
result.append(('[SetCursorPosition]', ''))
656653

657654
if checked:
658-
result.append((style, '*', mouse_handler))
655+
result.append((style, '*'))
659656
else:
660-
result.append((style, ' ', mouse_handler))
657+
result.append((style, ' '))
661658

662-
result.append((style, ')', mouse_handler))
663-
result.append(('class:radio', ' ', mouse_handler))
659+
result.append((style, ')'))
660+
result.append(('class:radio', ' '))
664661
result.extend(to_formatted_text(value[1], style='class:radio'))
665-
result.append(('', '\n', mouse_handler))
662+
result.append(('', '\n'))
663+
664+
# Add mouse handler to all fragments.
665+
for i in range(len(result)):
666+
result[i] = (result[i][0], result[i][1], mouse_handler)
666667

667668
result.pop() # Remove last newline.
668669
return result

0 commit comments

Comments
 (0)