Velocity/core/modes.py

30 lines
683 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
2022-03-19 15:57:38 +00:00
insert.activate()
2022-03-19 15:13:28 +00:00
elif mode == "normal":
2022-03-19 15:41:40 +00:00
# Activate normal mode
2022-03-19 15:57:38 +00:00
normal.activate()
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)