Velocity/mode/insert.py

30 lines
721 B
Python
Raw Normal View History

2022-04-17 13:33:16 +01:00
import curses
2022-04-17 13:32:35 +01:00
from core import cursors, modes
2022-03-19 15:13:28 +00:00
def execute(instance, key):
if key == 27: # Escape
2022-03-19 15:13:28 +00:00
# Switch to normal mode
2022-03-19 15:41:40 +00:00
modes.activate(instance, "normal")
2022-03-19 15:13:28 +00:00
2022-04-17 13:32:35 +01:00
elif key in (curses.KEY_BACKSPACE, 127, '\b'): # Backspace
if instance.cursor[1] > 0:
# Delete the character before the cursor
instance.buffer.delete_char(instance)
# Move the cursor one to the left
cursors.push(instance, 3)
else:
# Insert the character
instance.buffer.insert_char(instance, chr(key))
# Move the cursor one to the right
cursors.push(instance, 1)
2022-03-19 15:13:28 +00:00
2022-03-19 15:57:38 +00:00
def activate():
2022-03-19 15:13:28 +00:00
# Switch the cursor to a line
2022-03-19 19:19:25 +00:00
cursors.mode("line")