45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from fide import *
|
|
|
|
global ctx
|
|
ctx = GlobalContext()
|
|
|
|
def cursor_go_left():
|
|
buf = ctx.current_buffer
|
|
cursor = ctx.current_buffer.cursor
|
|
if cursor.col == 0:
|
|
if cursor.line_num > 0:
|
|
cursor.col = buf.lines[cursor.line_num-1].length
|
|
cursor.want_col = cursor.col
|
|
cursor.line_num -= 1
|
|
else:
|
|
cursor.col = max(0, cursor.col - 1)
|
|
cursor.want_col = cursor.col
|
|
|
|
def cursor_go_right():
|
|
buf = ctx.current_buffer
|
|
cursor = ctx.current_buffer.cursor
|
|
if cursor.col == buffer_line_len(buf):
|
|
if cursor.line_num < buffer_total_lines(buf) - 1:
|
|
cursor.col = 0
|
|
cursor.want_col = cursor.col
|
|
cursor.line_num += 1
|
|
else:
|
|
cursor.col = min(buffer_line_len(buf), cursor.col + 1)
|
|
cursor.want_col = cursor.col
|
|
|
|
def cursor_go_down():
|
|
buf = ctx.current_buffer
|
|
cursor = ctx.current_buffer.cursor
|
|
line_len = buffer_line_len(buf)
|
|
cursor.line_num = min(len(buf.lines) - 1, cursor.line_num + 1)
|
|
cursor.col = min(cursor.want_col, line_len)
|
|
|
|
def cursor_go_up():
|
|
buf = ctx.current_buffer
|
|
cursor = ctx.current_buffer.cursor
|
|
cursor.line_num = max(0, cursor.line_num - 1)
|
|
line_len = buffer_line_len(buf)
|
|
# TODO: This should be global
|
|
line_len = 20
|
|
cursor.col = min(cursor.want_col, line_len)
|