Skip to content

Commit

Permalink
fix(masked input): highlight selected text
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Jan 25, 2025
1 parent dc71564 commit f207df0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/textual/widgets/_masked_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,19 @@ def render_line(self, y: int) -> Strip:
if char == " ":
result.stylize(style, index, index + 1)

if self._cursor_visible and self.has_focus:
if self._cursor_at_end:
result.pad_right(1)
cursor_style = self.get_component_rich_style("input--cursor")
cursor = self.cursor_position
result.stylize(cursor_style, cursor, cursor + 1)
if self.has_focus:
if not self.selection.is_empty:
start, end = self.selection
start, end = sorted((start, end))
selection_style = self.get_component_rich_style("input--selection")
result.stylize_before(selection_style, start, end)

if self._cursor_visible:
cursor_style = self.get_component_rich_style("input--cursor")
cursor = self.cursor_position
if self._cursor_at_end:
result.pad_right(1)
result.stylize(cursor_style, cursor, cursor + 1)

segments = list(result.render(self.app.console))
line_length = Segment.get_line_length(segments)
Expand Down

0 comments on commit f207df0

Please sign in to comment.