Handle invalid line number entries on GoTo
This commit is contained in:
parent
79c43b7416
commit
4d38040567
1 changed files with 11 additions and 6 deletions
|
|
@ -354,19 +354,25 @@ def editor(stdscr, filename, mouse=None, terminal_tilegrid=None): # pylint: dis
|
||||||
find_command = False
|
find_command = False
|
||||||
|
|
||||||
elif goto_command:
|
elif goto_command:
|
||||||
cursor.row = clamp(int(user_response) - 1, 0, len(buffer) - 1)
|
if user_response.isdigit():
|
||||||
window.row = clamp(cursor.row - window.n_rows // 2, 0, len(buffer) - window.n_rows)
|
cursor.row = clamp(int(user_response) - 1, 0, len(buffer) - 1)
|
||||||
cursor.col = 0
|
window.row = clamp(cursor.row - window.n_rows // 2, 0, len(buffer) - window.n_rows)
|
||||||
window.horizontal_scroll(cursor)
|
cursor.col = 0
|
||||||
|
window.horizontal_scroll(cursor)
|
||||||
|
|
||||||
user_response = ""
|
user_response = ""
|
||||||
goto_command = False
|
goto_command = False
|
||||||
|
|
||||||
elif k == "\x7f": # backspace
|
elif k == "\x7f" or k == "\x08": # backspace
|
||||||
user_response = user_response[:-1]
|
user_response = user_response[:-1]
|
||||||
elif k == "\x1b": # escape
|
elif k == "\x1b": # escape
|
||||||
user_prompt = None
|
user_prompt = None
|
||||||
user_response = ""
|
user_response = ""
|
||||||
|
else:
|
||||||
|
print(f"unhandled k: {k}")
|
||||||
|
print(f"unhandled K: {ord(k)}")
|
||||||
|
print(f"unhandled k: {bytes(k, 'utf-8')}")
|
||||||
|
|
||||||
elif len(k) == 1 and " " <= k <= "~":
|
elif len(k) == 1 and " " <= k <= "~":
|
||||||
buffer.insert(cursor, k)
|
buffer.insert(cursor, k)
|
||||||
for _ in k:
|
for _ in k:
|
||||||
|
|
@ -442,7 +448,6 @@ def editor(stdscr, filename, mouse=None, terminal_tilegrid=None): # pylint: dis
|
||||||
elif k == "KEY_LEFT":
|
elif k == "KEY_LEFT":
|
||||||
left(window, buffer, cursor)
|
left(window, buffer, cursor)
|
||||||
elif k == "KEY_DOWN":
|
elif k == "KEY_DOWN":
|
||||||
|
|
||||||
cursor.down(buffer)
|
cursor.down(buffer)
|
||||||
window.down(buffer, cursor)
|
window.down(buffer, cursor)
|
||||||
window.horizontal_scroll(cursor)
|
window.horizontal_scroll(cursor)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue