чување 1959aa296ddaa36886cfd698fdb3d0f6e8f986b2
родитељ 0c90bc5c0cf6931b50b85be63e42566df280346b
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sat, 26 Feb 2022 19:47:01 +0100
Add C-Y/d (=erase line); update TODO
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 5, додавања: 42(+), брисања: 13(-)
diff --git a/TODO b/TODO
@@ -1,19 +1,9 @@
TODO
====
- [x] Reassign C-I (clash with inserting tab!)
-
- [/] When updating first_shown_column in insert_line, set it to (maxy - 2) / 2
-
- [x] Copy/paste?
-
- [x] Overwrite mode
-
[ ] Investigate DrawState.first_shown_column
- [ ] Add vi V
-
- [x] Add Z as vi-like shortcut for C-S
+ [/] Add vi V
< > Search?
diff --git a/config.def.h b/config.def.h
@@ -42,6 +42,7 @@ int enter_command_mode(struct DrawState* state);
int enter_insert_mode(struct DrawState* state);
int erase_backwards(struct DrawState* state);
int erase_forward(struct DrawState* state);
+int erase_line(struct DrawState* state);
int erase_to_end(struct DrawState* state);
int erase_to_start(struct DrawState* state);
int exit_program(struct DrawState* state);
@@ -137,6 +138,8 @@ static const struct Key global_keys[] = {
.callback = erase_to_start },
{ .ev = { .key = TB_KEY_CTRL_V },
.callback = paste_from_paste },
+ { .ev = { .key = TB_KEY_CTRL_Y },
+ .callback = erase_line },
{ .ev = { .key = TB_KEY_DELETE },
.callback = erase_forward },
{ .ev = { .key = TB_KEY_F1 }, .callback = show_help },
@@ -202,6 +205,7 @@ static const struct Key command_keys[] = {
{ .ev = { .ch = ':' }, .callback = show_go_to_line },
{ .ev = { .ch = '0' }, .callback = move_start },
{ .ev = { .ch = '$' }, .callback = move_end },
+ { .ev = { .ch = 'd' }, .callback = erase_line },
{ .ev = { .ch = 'G' }, .callback = move_bottom },
{ .ev = { .ch = 'g' }, .callback = move_top },
{ .ev = { .ch = 'H' }, .callback = move_screen_top },
@@ -218,6 +222,7 @@ static const struct Key command_keys[] = {
{ .ev = { .ch = 'v' }, .callback = toggle_selection },
{ .ev = { .ch = 'W' }, .callback = move_prev_word },
{ .ev = { .ch = 'w' }, .callback = move_next_word },
+ { .ev = { .ch = 'x' }, .callback = erase_forward },
{ .ev = { .ch = 'y' }, .callback = yank_to_paste },
{ .ev = { .ch = 'Z' }, .callback = write_file }
};
diff --git a/config.h b/config.h
@@ -42,6 +42,7 @@ int enter_command_mode(struct DrawState* state);
int enter_insert_mode(struct DrawState* state);
int erase_backwards(struct DrawState* state);
int erase_forward(struct DrawState* state);
+int erase_line(struct DrawState* state);
int erase_to_end(struct DrawState* state);
int erase_to_start(struct DrawState* state);
int exit_program(struct DrawState* state);
@@ -137,6 +138,8 @@ static const struct Key global_keys[] = {
.callback = erase_to_start },
{ .ev = { .key = TB_KEY_CTRL_V },
.callback = paste_from_paste },
+ { .ev = { .key = TB_KEY_CTRL_Y },
+ .callback = erase_line },
{ .ev = { .key = TB_KEY_DELETE },
.callback = erase_forward },
{ .ev = { .key = TB_KEY_F1 }, .callback = show_help },
@@ -202,6 +205,7 @@ static const struct Key command_keys[] = {
{ .ev = { .ch = ':' }, .callback = show_go_to_line },
{ .ev = { .ch = '0' }, .callback = move_start },
{ .ev = { .ch = '$' }, .callback = move_end },
+ { .ev = { .ch = 'd' }, .callback = erase_line },
{ .ev = { .ch = 'G' }, .callback = move_bottom },
{ .ev = { .ch = 'g' }, .callback = move_top },
{ .ev = { .ch = 'H' }, .callback = move_screen_top },
@@ -218,6 +222,7 @@ static const struct Key command_keys[] = {
{ .ev = { .ch = 'v' }, .callback = toggle_selection },
{ .ev = { .ch = 'W' }, .callback = move_prev_word },
{ .ev = { .ch = 'w' }, .callback = move_next_word },
+ { .ev = { .ch = 'x' }, .callback = erase_forward },
{ .ev = { .ch = 'y' }, .callback = yank_to_paste },
{ .ev = { .ch = 'Z' }, .callback = write_file }
};
diff --git a/sled.1.in b/sled.1.in
@@ -109,6 +109,7 @@ _
\fCC-T\fP@Go to next word
\fCC-U\fP@Erase to start of line
\fCC-V\fP@Paste from paste buffer
+\fCC-Y\fP@Erase the entire current line
.TE
.
.sp 1
@@ -138,6 +139,7 @@ _
\fC:\fP@Show Go to line dialog
\fC0\fP@Go to start of line
\fC$\fP@Go to end of line
+\fCd\fP@Erase the entire current line
\fCG\fP@Go to last line in the file
\fCg\fP@Go to first line in the file
\fCH\fP@Go to first line on the screen
@@ -154,6 +156,7 @@ _
\fCv\fP@Toggle selection mode
\fCW\fP@Go to previous word
\fCw\fP@Go to next word
+\fCx\fP@Erase character under cursor
\fCy\fP@Yank to paste buffer
\fCZ\fP@Write (save) file
.TE
diff --git a/sled.c b/sled.c
@@ -1207,6 +1207,32 @@ erase_forward(struct DrawState* state)
}
int
+erase_line(struct DrawState* state)
+{
+ struct BufferLine* current = NULL;
+ if (state->rows_count == 1)
+ {
+ *state->buffer[0].text = 0;
+ state->buffer[0].length = 0;
+ goto erase_line_done;
+ }
+ for (size_t row = state->row; row < state->rows_count - 1; row++)
+ {
+ current = state->buffer + row;
+ current->length = u32_strcpy(current->text,
+ state->buffer[row + 1].text);
+ }
+ *state->buffer[state->rows_count - 1].text = 0;
+ state->buffer[state->rows_count - 1].length = 0;
+ state->rows_count--;
+
+erase_line_done:
+ state->column = 0;
+ state->display_column = 0;
+ return 0;
+}
+
+int
erase_to_start(struct DrawState* state)
{
size_t i = state->column;
@@ -1348,7 +1374,7 @@ write_file(struct DrawState* state)
break;
default:
*state->error = 0;
- state->dirty = 0;
+ state->dirty = 0;
}
return 0;
@@ -2051,7 +2077,7 @@ init_termbox:
state.help_width = calculate_help_width(&state);
state.input_dialog_width
= calculate_input_dialog_width(&state);
- state.maxy = tb_height();
+ state.maxy = tb_height();
recalculate_size = 0;
}
if (!draw(&state))