Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Exposed `CollapsibleTitle` https://github.com/Textualize/textual/pull/5810

### Added

- Added `Color.hsv` property and `Color.from_hsv` class method https://github.com/Textualize/textual/pull/5803
- Added `cursor_at_start` and `cursor_at_end` properties to the `Input` widget https://github.com/Textualize/textual/pull/5830

## [3.2.0] - 2025-05-02

Expand Down
17 changes: 11 additions & 6 deletions src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,18 @@ def _position_to_cell(self, position: int) -> int:
def _cursor_offset(self) -> int:
"""The cell offset of the cursor."""
offset = self._position_to_cell(self.cursor_position)
if self._cursor_at_end:
if self.cursor_at_end:
offset += 1
return offset

@property
def _cursor_at_end(self) -> bool:
"""Flag to indicate if the cursor is at the end"""
def cursor_at_start(self) -> bool:
"""Flag to indicate if the cursor is at the start."""
return self.cursor_position == 0

@property
def cursor_at_end(self) -> bool:
"""Flag to indicate if the cursor is at the end."""
return self.cursor_position == len(self.value)

def check_consume_key(self, key: str, character: str | None) -> bool:
Expand Down Expand Up @@ -513,7 +518,7 @@ def _watch_cursor_blink(self, blink: bool) -> None:

@property
def cursor_screen_offset(self) -> Offset:
"""The offset of the cursor of this input in screen-space. (x, y)/(column, row)"""
"""The offset of the cursor of this input in screen-space. (x, y)/(column, row)."""
x, y, _width, _height = self.content_region
scroll_x, _ = self.scroll_offset
return Offset(x + self._cursor_offset - scroll_x, y)
Expand Down Expand Up @@ -640,7 +645,7 @@ def render_line(self, y: int) -> Strip:
if self._cursor_visible:
cursor_style = self.get_component_rich_style("input--cursor")
cursor = self.cursor_position
if not show_suggestion and self._cursor_at_end:
if not show_suggestion and self.cursor_at_end:
result.pad_right(1)
result.stylize(cursor_style, cursor, cursor + 1)

Expand Down Expand Up @@ -848,7 +853,7 @@ def action_cursor_right(self, select: bool = False) -> None:
if select:
self.selection = Selection(start, end + 1)
else:
if self._cursor_at_end and self._suggestion:
if self.cursor_at_end and self._suggestion:
self.value = self._suggestion
self.cursor_position = len(self.value)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/textual/widgets/_masked_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def render_line(self, y: int) -> Strip:
result.stylize(style, index, index + 1)

if self._cursor_visible and self.has_focus:
if self._cursor_at_end:
if self.cursor_at_end:
result.pad_right(1)
cursor_style = self.get_component_rich_style("input--cursor")
cursor = self.cursor_position
Expand Down
Loading