чување 4a42dc33bc72ee4c478982d4fb7dac740ecd719b
родитељ d0715e9fdb7ac6cb70d826d6a8f01fb1798f69e8
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 28 Sep 2023 18:48:42 +0200
Pressing h/Left on the start of line goes to the end of previous line; pressing
l/Right on the end of line goes to the start of next line
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 3, додавања: 30(+), брисања: 11(-)
diff --git a/TODO b/TODO
@@ -1,14 +1,6 @@
TODO
====
-[ ] Pressing h/Left on the start of line should go to the end of previous line,
- similar for l/Right and beginning of next line
-
-</> CLI interface? Example:
- sled -c '^\G$^\\nSome text at the end^\^L10\ng/text\n' file.txt
- (wq would be assumed.)
- - Con: this would overlap with sed(1), with far less actual features.
-
[~] Code optimization (struct coord...)
diff --git a/TODO.done b/TODO.done
@@ -0,0 +1,10 @@
+Done or canceled todos
+======================
+
+[x] Pressing h/Left on the start of line should go to the end of previous line,
+ similar for l/Right and beginning of next line
+
+</> CLI interface? Example:
+ sled -c '^\G$^\\nSome text at the end^\^L10\ng/text\n' file.txt
+ (wq would be assumed.)
+ - Con: this would overlap with sed(1), with far less actual features.
diff --git a/sled.c b/sled.c
@@ -706,11 +706,28 @@ position_to(struct DrawState* state, const int row, const int column)
{
state->coord.col = column;
if (state->coord.col < 0)
- state->coord.col = 0;
+ {
+ if (state->coord.row > 0)
+ {
+ state->coord.row--;
+ state->coord.col
+ = state->buffer[state->coord.row].length;
+ }
+ else
+ state->coord.col = 0;
+ }
else if (state->coord.col
> (int)state->buffer[state->coord.row].length)
- state->coord.col
- = state->buffer[state->coord.row].length;
+ {
+ if (state->coord.row + 1 < state->rows_count)
+ {
+ state->coord.row++;
+ state->coord.col = 0;
+ }
+ else
+ state->coord.col
+ = state->buffer[state->coord.row].length;
+ }
state->display_column = display_length(state,
state->buffer[state->coord.row].text, state->coord.col);
state->saved_column = state->display_column;