Skip to content

Commit 8be6eb8

Browse files
author
Jonathan Plasse
committed
Keep the cursor position for bad inputs
1 parent 46df6f9 commit 8be6eb8

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
@@ -619,8 +619,14 @@ def replace(self, text: str, start: int, end: int):
619619
end: End index to replace (inclusive).
620620
"""
621621

622+
old_cursor_position = self.cursor_position
622623
self.cursor_position = start
623-
self.insert_text_at_cursor(text)
624+
new_value = self._template.insert_text_at_cursor(text)
625+
if new_value is not None:
626+
self.value, self.cursor_position = new_value
627+
else:
628+
self.cursor_position = old_cursor_position
629+
self.restricted()
624630

625631
def clear(self) -> None:
626632
"""Clear the masked input."""

0 commit comments

Comments
 (0)