Skip to content

Commit 2d41f74

Browse files
authored
fix: patch crash for backspace in integer input (#32)
- IntegerInput will cause the app to crash if there is no input present in the IntegerInput and backspace key is pressed
1 parent 4818130 commit 2d41f74

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/textual_inputs/integer_input.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IntegerInput(Widget):
2828
name (Optional[str]): The unique name of the widget. If None, the
2929
widget will be automatically named.
3030
value (Optional[int]): The starting integer value.
31-
placeholder (Union[str, int, optional): Defaults to "". Text that
31+
placeholder (Union[str, int], optional): Defaults to "". Text that
3232
appears in the widget when value is "" and the widget is not focused.
3333
title (str, optional): Defaults to "". A title on the top left
3434
of the widget's border.
@@ -268,11 +268,13 @@ async def on_key(self, event: events.Key) -> None:
268268
self.value = int(value[:-1])
269269
self._cursor_position -= 1
270270
else:
271-
self.value = int(
271+
new_value = (
272272
value[: self._cursor_position - 1]
273273
+ value[self._cursor_position :]
274274
)
275-
self._cursor_position -= 1
275+
if new_value != "":
276+
self.value = int(new_value)
277+
self._cursor_position -= 1
276278

277279
await self._emit_on_change(event)
278280

0 commit comments

Comments
 (0)