Skip to content

Commit b042f75

Browse files
author
Jonathan Plasse
committed
Keep the cursor position for bad inputs
1 parent 47a8120 commit b042f75

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/textual/widgets/_masked_input.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,14 @@ def replace(self, text: str, start: int, end: int):
627627
end: End index to replace (inclusive).
628628
"""
629629

630+
old_cursor_position = self.cursor_position
630631
self.cursor_position = start
631-
self.insert_text_at_cursor(text)
632+
new_value = self._template.insert_text_at_cursor(text)
633+
if new_value is not None:
634+
self.value, self.cursor_position = new_value
635+
else:
636+
self.cursor_position = old_cursor_position
637+
self.restricted()
632638

633639
def clear(self) -> None:
634640
"""Clear the masked input."""

0 commit comments

Comments
 (0)