poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 6b26e32b9404f09e70483df1f6ac741b31212591
родитељ e6a21d78b2a21ec3eb26625b1458aab480683551
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sun, 27 Jun 2021 21:54:27 +0200

Added erase to end, C-K and update and previous/next, C-P/C-N; edit box status line background fill fix

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mdraw.c | 2+-
Mpoe.1.in | 3+++
Mpoe.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
измењених датотека: 3, додавања: 62(+), брисања: 19(-)

diff --git a/draw.c b/draw.c @@ -279,7 +279,7 @@ draw_editbox(const struct DrawState* state) state->input_first_shown_row, state->input_rows_count); draw_string(startx+1, endy-2, DLG_FG, DLG_BG, - sbuf, w-2, w-2, 1, 1, LEFT); + sbuf, w-2, strlen(sbuf)+2, 1, 1, LEFT); if (entry->flags != FL_NONE) if (!draw_string(endx-MAXFLAGSBUF-4-5, endy-2, DLG_FG, DLG_BG, flags_buf, MAXFLAGSBUF+4-1, MAXFLAGSBUF+4-1, 0, diff --git a/poe.1.in b/poe.1.in @@ -62,11 +62,14 @@ l l. \fBKey\fR@\fBAction\fR _ \fCC-S\fR@Update entry and close dialog +\fCC-P or PgUp@Update entry and edit previous entry +\fCC-N or PgDn@Update entry and edit next entry \fCEscape\fR@Cancel changes and close dialog \fCC-F\fR@Toggle fuzzy flag \fCC-A\fR or \fCHome\fR@Go to start of line \fCC-E\fR or \fCEnd\fR@Go to end of line \fCC-U\fR@Erase to start of line +\fCC-K\fR@Erase to end of line \fC\[ua]\fR@Go to previous line \fC\[<-]\fR@Go to previous character \fC\[->]\fR@Go to next character diff --git a/poe.c b/poe.c @@ -100,6 +100,8 @@ void move_end(struct DrawState* state); size_t display_length(const struct DrawState* state, const size_t max_index); size_t input_length(const struct DrawState* state, const size_t max_index); void insert_char(struct DrawState* state, uint32_t ch); +void erase_to_start(struct DrawState* state); +void erase_to_end(struct DrawState* state); struct DrawState* insert_line(struct DrawState* state); struct DrawState* join_lines(struct DrawState* state, size_t first_line); @@ -377,6 +379,33 @@ insert_char(struct DrawState* state, uint32_t ch) - EDIT_WIDTH+5; } +void +erase_to_start(struct DrawState* state) +{ + size_t i = state->input_column; + struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; + size_t len = buffer_line->length; + do + { + buffer_line->text[i-state->input_column] = + buffer_line->text[i]; + i++; + } + while (buffer_line->text[i]); + buffer_line->text[len-state->input_column] = 0; + buffer_line->length = len-state->input_column; + move_start(state); +} + +void +erase_to_end(struct DrawState* state) +{ + struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; + buffer_line->text[state->input_column] = 0; + buffer_line->length = state->input_column; + move_end(state); +} + struct DrawState* insert_line(struct DrawState* state) { @@ -462,7 +491,6 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) struct PoEntry* entry = &state->entries[state->msgid_number-1]; struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; - size_t len = buffer_line->length; if (state->error[0]) state->error[0] = 0; @@ -473,11 +501,9 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) if (ev->key == TB_KEY_ARROW_DOWN) move_down(state); - else if (ev->key == TB_KEY_ARROW_LEFT - || ev->key == TB_KEY_CTRL_P) + else if (ev->key == TB_KEY_ARROW_LEFT ) move_left(state); - else if (ev->key == TB_KEY_ARROW_RIGHT - || ev->key == TB_KEY_CTRL_N) + else if (ev->key == TB_KEY_ARROW_RIGHT) move_right(state); else if (ev->key == TB_KEY_ARROW_UP) move_up(state); @@ -527,19 +553,9 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR); } else if (ev->key == TB_KEY_CTRL_U) - { - size_t i = state->input_column; - do - { - buffer_line->text[i-state->input_column] = - buffer_line->text[i]; - i++; - } - while (buffer_line->text[i]); - buffer_line->text[len-state->input_column] = 0; - buffer_line->length = len-state->input_column; - move_start(state); - } + erase_to_start(state); + else if (ev->key == TB_KEY_CTRL_K) + erase_to_end(state); else if (ev->key == TB_KEY_DELETE) { if (buffer_line->text[state->input_column]) @@ -574,6 +590,30 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) else if (ev->key == TB_KEY_HOME || ev->key == TB_KEY_CTRL_A) move_start(state); + else if (ev->key == TB_KEY_PGDN + || ev->key == TB_KEY_CTRL_N) + { + save_msgstr(state); + if (state->msgid_number != state->msgid_count) + state->msgid_number++; + load_msgstr(state); + state->input_row = 0; + state->input_first_shown_row = 0; + move_start(state); + state->error[0] = 0; + } + else if (ev->key == TB_KEY_PGUP + || ev->key == TB_KEY_CTRL_P) + { + save_msgstr(state); + if (state->msgid_number != 0) + state->msgid_number--; + load_msgstr(state); + state->input_row = 0; + state->input_first_shown_row = 0; + move_start(state); + state->error[0] = 0; + } else if (ev->key == TB_KEY_SPACE) insert_char(state, ' '); else if (ev->key == TB_KEY_TAB)