Velocity/mode/insert.py
2022-04-17 13:33:16 +01:00

30 lines
721 B
Python

import curses
from core import cursors, modes
def execute(instance, key):
if key == 27: # Escape
# Switch to normal mode
modes.activate(instance, "normal")
elif key in (curses.KEY_BACKSPACE, 127, '\b'): # Backspace
if instance.cursor[1] > 0:
# Delete the character before the cursor
instance.buffer.remove_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)
def activate():
# Switch the cursor to a line
cursors.mode("line")