Quellcode durchsuchen

Adding keybind to go to start/end of line

Vinicius Teshima vor 1 Jahr
Ursprung
Commit
ebe16ca625
2 geänderte Dateien mit 51 neuen und 0 gelöschten Zeilen
  1. 12 0
      src/config.h
  2. 39 0
      src/keybind.h

+ 12 - 0
src/config.h

@@ -54,6 +54,18 @@ static struct keybinds keybinds[KMS] = {
 		.binds = {
 			{KMOD_ALT, keybind_delete_word, {.dir = DIR_FORWARD}}
 		}
+	},
+	[SDLK_a % KMS] = {
+		.size = 1,
+		.binds = {
+			{KMOD_CTRL, keybind_mv_cur_beg_line, {.ptr = NULL}}
+		}
+	},
+	[SDLK_e % KMS] = {
+		.size = 1,
+		.binds = {
+			{KMOD_CTRL, keybind_mv_cur_end_line, {.ptr = NULL}}
+		}
 	}
 };
 

+ 39 - 0
src/keybind.h

@@ -36,6 +36,9 @@ struct app keybind_delete_char(struct app app, union keybind_args args);
 struct app keybind_mv_cur_word(struct app app, union keybind_args args);
 struct app keybind_delete_word(struct app app, union keybind_args args);
 
+struct app keybind_mv_cur_beg_line(struct app app, union keybind_args args);
+struct app keybind_mv_cur_end_line(struct app app, union keybind_args args);
+
 struct app keybind_insert_newline(struct app app, union keybind_args args);
 
 
@@ -141,6 +144,42 @@ keybind_delete_word(struct app app, union keybind_args args)
 	return app;
 }
 
+struct app
+keybind_mv_cur_beg_line(struct app app, union keybind_args args)
+{
+	(void) args;
+	size_t index;
+	enum buffer_err err;
+	RET_UNWRAP2(index, err, struct ret_size_t_err,
+		    buffer_index_bw_char(app.buf, app.buf.cur - 1, '\n'));
+	if ( err != BUFFER_ERR_OK ) {
+		if ( err == BUFFER_ERR_NOT_FOUND ) {
+			app.buf.cur = 0;
+		}
+		return app;
+	}
+	app.buf.cur = index + 1;
+	return app;
+}
+
+struct app
+keybind_mv_cur_end_line(struct app app, union keybind_args args)
+{
+	(void) args;
+	size_t index;
+	enum buffer_err err;
+	RET_UNWRAP2(index, err, struct ret_size_t_err,
+		    buffer_index_fw_char(app.buf, app.buf.cur + 1, '\n'));
+	if ( err != BUFFER_ERR_OK ) {
+		if ( err == BUFFER_ERR_NOT_FOUND ) {
+			app.buf.cur = app.buf.data.size;
+		}
+		return app;
+	}
+	app.buf.cur = index;
+	return app;
+}
+
 struct app
 keybind_insert_newline(struct app app, union keybind_args args)
 {