Velocity/core/modes.py

30 lines
699 B
Python
Raw Normal View History

2022-03-19 15:13:28 +00:00
from mode import normal, insert, command
2022-03-19 15:41:40 +00:00
def activate(instance, mode):
2022-03-19 15:13:28 +00:00
# Visibly update the mode
instance.mode = mode
instance.update()
if mode == "command":
2022-03-19 15:41:40 +00:00
# Activate command mode
command.activate(instance)
2022-03-19 15:13:28 +00:00
elif mode == "insert":
2022-03-19 15:41:40 +00:00
# Activate insert mode
insert.activate(instance)
2022-03-19 15:13:28 +00:00
elif mode == "normal":
2022-03-19 15:41:40 +00:00
# Activate normal mode
normal.activate(instance)
2022-03-19 15:13:28 +00:00
def handle_key(instance, key):
2022-03-19 15:41:40 +00:00
# Normal mode - default keybindings
2022-03-19 15:13:28 +00:00
if instance.mode == "normal":
2022-03-19 15:41:40 +00:00
normal.execute(instance, key)
2022-03-19 15:13:28 +00:00
# Insert mode - inserting text to the buffer
elif instance.mode == "insert":
2022-03-19 15:41:40 +00:00
insert.execute(instance, key)