Skip to content

Commit f207df0

Browse files
committed
fix(masked input): highlight selected text
Fixes #5495.
1 parent dc71564 commit f207df0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/textual/widgets/_masked_input.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,19 @@ def render_line(self, y: int) -> Strip:
569569
if char == " ":
570570
result.stylize(style, index, index + 1)
571571

572-
if self._cursor_visible and self.has_focus:
573-
if self._cursor_at_end:
574-
result.pad_right(1)
575-
cursor_style = self.get_component_rich_style("input--cursor")
576-
cursor = self.cursor_position
577-
result.stylize(cursor_style, cursor, cursor + 1)
572+
if self.has_focus:
573+
if not self.selection.is_empty:
574+
start, end = self.selection
575+
start, end = sorted((start, end))
576+
selection_style = self.get_component_rich_style("input--selection")
577+
result.stylize_before(selection_style, start, end)
578+
579+
if self._cursor_visible:
580+
cursor_style = self.get_component_rich_style("input--cursor")
581+
cursor = self.cursor_position
582+
if self._cursor_at_end:
583+
result.pad_right(1)
584+
result.stylize(cursor_style, cursor, cursor + 1)
578585

579586
segments = list(result.render(self.app.console))
580587
line_length = Segment.get_line_length(segments)

0 commit comments

Comments
 (0)