Skip to content

Commit

Permalink
Merge pull request #232 from Cube707/DELETE
Browse files Browse the repository at this point in the history
text: implement DELETE
  • Loading branch information
Cube707 authored Aug 14, 2022
2 parents 6bd3558 + a4768b4 commit 2800517
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/inquirer/render/console/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def process_input(self, pressed):
self.current = self.current[: n - 1] + self.current[n:]
else:
self.current = self.current[:-1]
elif pressed == key.SUPR:
if self.current and self.cursor_offset:
n = -self.cursor_offset
self.cursor_offset -= 1
if n < -1:
self.current = self.current[:n] + self.current[n + 1 :] # noqa E203
else:
self.current = self.current[:n]
elif pressed == key.LEFT:
if self.cursor_offset < len(self.current):
self.cursor_offset += 1
Expand Down
15 changes: 14 additions & 1 deletion tests/integration/console_render/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def raise_exc(x, current):
self.assertInStdout(message)
self.assertInStdout("Custom error")

def test_allows_deletion(self):
def test_allows_BACKSPACE_deletion(self):
stdin_array = ["a", key.BACKSPACE, "b", key.ENTER]
stdin = helper.event_factory(*stdin_array)
message = "Foo message"
Expand All @@ -111,6 +111,19 @@ def test_allows_deletion(self):

self.assertEqual("b", result)

def test_allows_DELETE_deletion(self):
stdin_array = ["a", "b", key.LEFT, key.LEFT, "c", key.SUPR, key.SUPR, key.ENTER]
stdin = helper.event_factory(*stdin_array)
message = "Foo message"
variable = "Bar variable"

question = questions.Text(variable, message)

sut = ConsoleRender(event_generator=stdin)
result = sut.render(question)

self.assertEqual("c", result)

def test_cursor_movement(self):
stdin_array = [
"a",
Expand Down

0 comments on commit 2800517

Please sign in to comment.