Extract more functions and add ctrl+key bindings
This commit is contained in:
parent
27ef7d7c93
commit
5cb2fd0fd7
@ -4,5 +4,7 @@ keymap = {
|
|||||||
'left': cursor_go_left,
|
'left': cursor_go_left,
|
||||||
'right': cursor_go_right,
|
'right': cursor_go_right,
|
||||||
'up': cursor_go_up,
|
'up': cursor_go_up,
|
||||||
'down': cursor_go_down
|
'down': cursor_go_down,
|
||||||
|
'C-e': cursor_go_line_end,
|
||||||
|
'C-a': cursor_go_line_beginning,
|
||||||
}
|
}
|
||||||
|
12
editing.py
12
editing.py
@ -43,12 +43,12 @@ def cursor_go_up():
|
|||||||
# TODO: This should be global
|
# TODO: This should be global
|
||||||
cursor.col = min(cursor.want_col, line_len)
|
cursor.col = min(cursor.want_col, line_len)
|
||||||
|
|
||||||
def cursor_go_beginning_line():
|
def cursor_go_line_beginning():
|
||||||
buf = ctx.current_buffer
|
buf = ctx.current_buffer
|
||||||
buf.cursor.col = 0
|
buf.cursor.col = 0
|
||||||
buf.cursor.want_col = buf.cursor.col
|
buf.cursor.want_col = buf.cursor.col
|
||||||
|
|
||||||
def cursor_go_end_line():
|
def cursor_go_line_end():
|
||||||
buf = ctx.current_buffer
|
buf = ctx.current_buffer
|
||||||
buf.cursor.col = buffer_line_len(buf)
|
buf.cursor.col = buffer_line_len(buf)
|
||||||
buf.cursor.want_col = buf.cursor.col
|
buf.cursor.want_col = buf.cursor.col
|
||||||
@ -111,6 +111,14 @@ def buffer_delete_next_character():
|
|||||||
curr_line.length -= 1
|
curr_line.length -= 1
|
||||||
cursor.want_col = cursor.col
|
cursor.want_col = cursor.col
|
||||||
|
|
||||||
|
def buffer_insert_char(c):
|
||||||
|
cursor = ctx.current_buffer.cursor
|
||||||
|
curr_line = buffer_line_current(ctx.current_buffer)
|
||||||
|
curr_line.piece.insert(c, cursor.col)
|
||||||
|
curr_line.length += 1
|
||||||
|
cursor.col += 1
|
||||||
|
cursor.want_col = cursor.col
|
||||||
|
|
||||||
def buffer_insert_text_at_cursor(text):
|
def buffer_insert_text_at_cursor(text):
|
||||||
cursor = ctx.current_buffer.cursor
|
cursor = ctx.current_buffer.cursor
|
||||||
curr_line = buffer_line_current(ctx.current_buffer)
|
curr_line = buffer_line_current(ctx.current_buffer)
|
||||||
|
26
fide.py
26
fide.py
@ -57,7 +57,7 @@ def buffer_total_lines(buf: Buffer) -> int:
|
|||||||
return len(buf.lines)
|
return len(buf.lines)
|
||||||
|
|
||||||
def buffer_line_len(buf: Buffer) -> int:
|
def buffer_line_len(buf: Buffer) -> int:
|
||||||
return buffer_line_current(buf).length
|
return buffer_line_current(buf).length
|
||||||
|
|
||||||
def translate_keyname(keyname: str) -> str:
|
def translate_keyname(keyname: str) -> str:
|
||||||
match keyname:
|
match keyname:
|
||||||
@ -133,10 +133,19 @@ def main():
|
|||||||
cursor_flash = 0
|
cursor_flash = 0
|
||||||
curr_line = buffer_line_current(current_buffer)
|
curr_line = buffer_line_current(current_buffer)
|
||||||
if event.mod == 64: # Right Ctrl
|
if event.mod == 64: # Right Ctrl
|
||||||
if event.key == pg.K_e:
|
# this is inefficient, might as well just pass the mod number
|
||||||
cursor_go_end_line()
|
# and make the mapping mod_num -> config_key
|
||||||
if event.key == pg.K_a:
|
mod_key = translate_keyname('left ctrl')
|
||||||
cursor_go_beginning_line()
|
|
||||||
|
if event.unicode:
|
||||||
|
# print(mod_key, event.key, event.unicode)
|
||||||
|
key = mod_key + pg.key.name(event.key)
|
||||||
|
if key in keymap:
|
||||||
|
keymap[key]()
|
||||||
|
# if event.key == pg.K_e:
|
||||||
|
# cursor_go_line_end()
|
||||||
|
# if event.key == pg.K_a:
|
||||||
|
# cursor_go_line_beginning()
|
||||||
if event.key == pg.K_RETURN:
|
if event.key == pg.K_RETURN:
|
||||||
src = buffer_line_current(current_buffer).piece.get_text()
|
src = buffer_line_current(current_buffer).piece.get_text()
|
||||||
# try:
|
# try:
|
||||||
@ -144,6 +153,8 @@ def main():
|
|||||||
# except:
|
# except:
|
||||||
# print('error evaluating line: ' + src[3:])
|
# print('error evaluating line: ' + src[3:])
|
||||||
console.runsource(src[3:])
|
console.runsource(src[3:])
|
||||||
|
elif pg.key.name(event.key) == 'escape':
|
||||||
|
pass
|
||||||
elif event.key == pg.K_RETURN:
|
elif event.key == pg.K_RETURN:
|
||||||
buffer_newline_at_pos()
|
buffer_newline_at_pos()
|
||||||
elif event.key == pg.K_BACKSPACE:
|
elif event.key == pg.K_BACKSPACE:
|
||||||
@ -155,10 +166,7 @@ def main():
|
|||||||
# pass
|
# pass
|
||||||
# elif event.mod < 2:
|
# elif event.mod < 2:
|
||||||
elif event.unicode:
|
elif event.unicode:
|
||||||
curr_line.piece.insert(event.unicode, cursor.col)
|
buffer_insert_char(event.unicode)
|
||||||
curr_line.length += 1
|
|
||||||
cursor.col += 1
|
|
||||||
cursor.want_col = cursor.col
|
|
||||||
|
|
||||||
for i,curr_line in enumerate(current_buffer.lines):
|
for i,curr_line in enumerate(current_buffer.lines):
|
||||||
render = text_renderer.render(curr_line.piece.get_text(), True, 'black')
|
render = text_renderer.render(curr_line.piece.get_text(), True, 'black')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user