чување a66ef27a0aa195e08265a5a040f9298058216ffa
родитељ cf2bb3e3a3330ae79f5b71809a52c4e031ad87e2
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 13 Feb 2022 21:52:27 +0100
Add <-/h ->/l
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | sled.c | | | 126 | ++++++++++++++++++++++++++++++------------------------------------------------- |
измењених датотека: 1, додавања: 48(+), брисања: 78(-)
diff --git a/sled.c b/sled.c
@@ -144,8 +144,9 @@ format_position(char* result, size_t result_size, const char* format,
if (!result)
return;
snprintf(result, result_size, format, state->column + 1, state->row + 1,
- state->rows_count ? (state->row * 100) / (state->rows_count - 1)
- : 0);
+ state->rows_count > 1
+ ? (state->row * 100) / (state->rows_count - 1)
+ : 0);
}
void
@@ -645,75 +646,49 @@ move_start(struct DrawState* state)
void
move_left(struct DrawState* state)
{
- /*
- if (state->edit_info_focused)
- {
- if (state->info_first_shown_column > 0)
- state->info_first_shown_column--;
+ if (state->column == 0)
return;
- }
- if (state->input_column == 0)
- return;
-
- if (state->input_buffer[state->input_row].text[state->input_column - 1]
+ if (state->buffer[state->row].text[state->column - 1]
== '\t')
- state->input_display_column = display_length(state,
- state->input_buffer[state->input_row].text,
- state->input_column - 1);
+ state->display_column = display_length(state,
+ state->buffer[state->row].text,
+ state->column - 1);
else
- state->input_display_column--;
- state->input_column--;
+ state->display_column--;
+ state->column--;
- if (state->input_display_column < state->input_first_shown_column)
- state->input_first_shown_column = state->input_display_column;
- */
+ if (state->display_column < state->first_shown_column)
+ state->first_shown_column = state->display_column;
}
void
move_right(struct DrawState* state)
{
- /*
- if (state->edit_info_focused)
- {
- if (state->info_first_shown_column + state->edit_width - 3
- < state->info_rows_maxlen + 1)
- state->info_first_shown_column++;
- return;
- }
-
- size_t len = state->input_buffer[state->input_row].length;
- if (state->input_column == len)
+ size_t len = state->buffer[state->row].length;
+ if (state->column == len)
return;
- if (state->input_buffer[state->input_row].text[state->input_column]
+ if (state->buffer[state->row].text[state->column]
== '\t')
- state->input_display_column = display_length(state,
- state->input_buffer[state->input_row].text,
- state->input_column + 1);
+ state->display_column = display_length(state,
+ state->buffer[state->row].text,
+ state->column + 1);
else
- state->input_display_column++;
- state->input_column++;
+ state->display_column++;
+ state->column++;
- if (state->input_display_column - state->input_first_shown_column
- > state->edit_width - 4)
- state->input_first_shown_column
- = state->input_display_column - state->edit_width + 4;
- */
+ if (state->display_column - state->first_shown_column
+ > state->maxx - 1)
+ state->first_shown_column
+ = state->display_column - state->maxx + 1;
}
void
move_prev_word(struct DrawState* state)
{
- /*
- if (state->edit_info_focused)
- {
- strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]);
- return;
- }
-
- int i = state->input_column;
- uint32_t* pline = state->input_buffer[state->input_row].text;
+ int i = state->column;
+ uint32_t* pline = state->buffer[state->row].text;
if (i > 0 && u32_is_word_boundary(pline[i - 1], 0))
i--;
@@ -723,42 +698,33 @@ move_prev_word(struct DrawState* state)
&& !u32_is_word_boundary(pline[i - 1], 0))
i--;
- state->input_column = i;
- state->input_display_column = display_length(state,
- state->input_buffer[state->input_row].text,
- state->input_column);
- if (state->input_display_column < state->input_first_shown_column)
- state->input_first_shown_column = state->input_display_column;
- */
+ state->column = i;
+ state->display_column = display_length(state,
+ state->buffer[state->row].text,
+ state->column);
+ if (state->display_column < state->first_shown_column)
+ state->first_shown_column = state->display_column;
}
void
move_next_word(struct DrawState* state)
{
- /*
- if (state->edit_info_focused)
- {
- strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]);
- return;
- }
-
- int i = state->input_column;
- uint32_t* pline = state->input_buffer[state->input_row].text;
- size_t len = state->input_buffer[state->input_row].length;
+ int i = state->column;
+ uint32_t* pline = state->buffer[state->row].text;
+ size_t len = state->buffer[state->row].length;
while (i < len && !u32_is_word_boundary(pline[i], 0))
i++;
while (i < len && u32_is_word_boundary(pline[i], 0))
i++;
- state->input_column = i;
- state->input_display_column = display_length(state,
- state->input_buffer[state->input_row].text,
- state->input_column);
- if (state->input_display_column - state->input_first_shown_column
- > state->edit_width - 4)
- state->input_first_shown_column
- = state->input_display_column - state->edit_width + 4;
- */
+ state->column = i;
+ state->display_column = display_length(state,
+ state->buffer[state->row].text,
+ state->column);
+ if (state->display_column - state->first_shown_column
+ > state->maxx - 1)
+ state->first_shown_column
+ = state->display_column - state->maxx + 1;
}
void
@@ -1321,6 +1287,10 @@ handle_key_event(struct tb_event* ev, struct DrawState* state)
strcpy(state->error, errors[ERR_DLG_OPEN]);
else if (ev->key == TB_KEY_ARROW_DOWN || ev->ch == 'j')
move_down(state);
+ else if (ev->key == TB_KEY_ARROW_LEFT || ev->ch == 'h')
+ move_left(state);
+ else if (ev->key == TB_KEY_ARROW_RIGHT || ev->ch == 'l')
+ move_right(state);
else if (ev->key == TB_KEY_ARROW_UP || ev->ch == 'k')
move_up(state);
else if (ev->key == TB_KEY_CTRL_B || ev->key == TB_KEY_PGUP)
@@ -1376,7 +1346,7 @@ handle_key_event(struct tb_event* ev, struct DrawState* state)
else if (ev->key == TB_KEY_F1 || ev->ch == 'H')
{
state->show_help = 1;
- state->error[0] = 0;
+ *state->error = 0;
}
else if (ev->key == TB_KEY_F3 || ev->ch == 'n')
; // next_match(state);