Velocity/mode/insert.py

30 lines
698 B
Python
Raw Normal View History

import curses
from core import cursors, modes, utils
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
elif key == 127: # 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)
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")