tAdd G for moving to specific line - ledit - Text editor (WIP) | |
git clone git://lumidify.org/ledit.git (fast, but not encrypted) | |
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow) | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit e5841801447358ed8f2f57e3dc0adc2873fb500e | |
parent 7d04a4c57facdf6080ce5492979b2652cd675a25 | |
Author: lumidify <[email protected]> | |
Date: Mon, 1 Nov 2021 10:46:58 +0100 | |
Add G for moving to specific line | |
Diffstat: | |
M keys_basic.c | 32 +++++++++++++++++++++++++++++… | |
M keys_basic_config.h | 2 ++ | |
2 files changed, 34 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/keys_basic.c b/keys_basic.c | |
t@@ -374,6 +374,38 @@ get_key_repeat(void) { | |
return num; | |
} | |
+static struct action | |
+move_to_line(ledit_buffer *buffer, char *text, int len) { | |
+ (void)text; | |
+ (void)len; | |
+ int repeat = get_key_repeat(); | |
+ int line; | |
+ if (repeat > 0) | |
+ line = repeat > buffer->lines_num ? buffer->lines_num : repeat; | |
+ else if (repeat == 0) | |
+ line = buffer->lines_num; | |
+ else | |
+ ledit_window_show_message(buffer->window, "Invalid key", -1); | |
+ if (repeat >= 0) { | |
+ ledit_buffer_wipe_line_cursor_attrs(buffer, buffer->cur_line); | |
+ buffer->cur_line = line - 1; | |
+ buffer->cur_index = 0; | |
+ int text_w, text_h; | |
+ PangoRectangle strong, weak; | |
+ ledit_window_get_textview_size(buffer->window, &text_w, &text_… | |
+ ledit_line *ll = ledit_buffer_get_line(buffer, buffer->cur_lin… | |
+ pango_layout_get_cursor_pos(ll->layout, 0, &strong, &weak); | |
+ /* if cursor is not on screen anymore, move to middle of scree… | |
+ if (ll->y_offset < buffer->display_offset || | |
+ ll->y_offset + strong.height / PANGO_SCALE > buffer->displ… | |
+ ledit_buffer_scroll(buffer, ll->y_offset - text_h / 2); | |
+ } | |
+ ledit_buffer_set_line_cursor_attrs(buffer, buffer->cur_line, b… | |
+ } | |
+ discard_repetition_stack(); | |
+ return (struct action){ACTION_NONE, NULL}; | |
+} | |
+ | |
static void | |
scroll_lines(ledit_buffer *buffer, int lines, int dir) { | |
int final_lines; | |
diff --git a/keys_basic_config.h b/keys_basic_config.h | |
t@@ -63,6 +63,7 @@ static struct action scroll_with_cursor_up(ledit_buffer *buf… | |
static struct action scroll_with_cursor_down(ledit_buffer *buffer, char *text,… | |
static struct action scroll_lines_up(ledit_buffer *buffer, char *text, int len… | |
static struct action scroll_lines_down(ledit_buffer *buffer, char *text, int l… | |
+static struct action move_to_line(ledit_buffer *buffer, char *text, int len); | |
/* FIXME: maybe sort these and use binary search | |
-> but that would mess with the catch-all keys */ | |
t@@ -119,6 +120,7 @@ static struct key keys_en[] = { | |
{"y", ControlMask, 0, NORMAL, KEY_ANY, KEY_NUMBERALLOWED, &scroll_wit… | |
{"d", ControlMask, 0, NORMAL, KEY_ANY, KEY_NUMBERALLOWED, &scroll_lin… | |
{"u", ControlMask, 0, NORMAL, KEY_ANY, KEY_NUMBERALLOWED, &scroll_lin… | |
+ {"G", 0, 0, NORMAL, KEY_ANY, KEY_NUMBERALLOWED, &move_to_line}, | |
{"", 0, 0, INSERT, KEY_ANY, KEY_ANY, &insert_mode_insert_text} | |
}; | |