Skip to content

Commit

Permalink
feat(number): auto adjust cursor position for negative toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhala committed Dec 7, 2021
1 parent 4df3fbb commit 318b2bf
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions InquirerPy/prompts/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,17 @@ def _handle_negative_toggle(self, _) -> None:
self._whole_buffer.text = "0"
return
if self._whole_buffer.text.startswith("-"):
move_cursor = self._whole_buffer.cursor_position < len(
self._whole_buffer.text
)
self._whole_buffer.text = self._whole_buffer.text[1:]
if move_cursor:
self._whole_buffer.cursor_position -= 1
else:
move_cursor = self._whole_buffer.cursor_position != 0
self._whole_buffer.text = f"-{self._whole_buffer.text}"
if move_cursor:
self._whole_buffer.cursor_position += 1

def _on_whole_text_change(self, buffer: Buffer) -> None:
self._whole_width = len(buffer.text) + 1
Expand Down

0 comments on commit 318b2bf

Please sign in to comment.