чување 6e6546c95da52a2594e0deebe3b3e4491a9476e0
родитељ 97999bc88b436de47c1f6ad67b38e00ee72c5934
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Fri, 2 Jul 2021 23:05:00 +0200
Working page up/down; changes: C-Z = fuzzy, C-F = pgdn/edit+next, C-B = pgup/edit+prev
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | TODO | | | 2 | +- |
| M | draw.c | | | 22 | ++++++++++++---------- |
| M | poe.1.in | | | 12 | +++++++----- |
| M | poe.c | | | 170 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
измењених датотека: 4, додавања: 135(+), брисања: 71(-)
diff --git a/TODO b/TODO
@@ -48,7 +48,7 @@
[ ] Multiline msgid display
- [ ] PgUp/PgDn (C-F/C-B, C-D instead to not clash with fuzzy?) in list
+ [x] PgUp/PgDn (C-F/C-B, C-D instead to not clash with fuzzy?) in list
display scroll by screenful; will also fix crash related to main
list scrolling past the initial screen height
diff --git a/draw.c b/draw.c
@@ -12,15 +12,17 @@
static const char* help_title = "poe - .po File Editor";
static const char* help[] = {
- "Esc - Close dialog, clear error",
- "Enter - Edit entry",
- "H or F1 - Show this screen",
- "g or Home - Go to first entry",
- "k or \u2191 - Go to previous entry",
- "j or \u2193 - Go to next entry",
- "G or End - Go to last entry",
- "f or C-F - Toggle fuzzy flag",
- "q or C-Q - Quit"
+ "Esc - Close dialog, clear error",
+ "Enter - Edit entry",
+ "H or F1 - Show this screen",
+ "g or Home - Go to first entry",
+ "C-B or PgUp - Go to previous page",
+ "k or \u2191 - Go to previous entry",
+ "j or \u2193 - Go to next entry",
+ "C-F or PgDn - Go to next page",
+ "G or End - Go to last entry",
+ "f or C-Z - Toggle fuzzy flag",
+ "q or C-Q - Quit"
};
static const char* editbox_title = "Edit translation";
const char* errors[] = {
@@ -340,7 +342,7 @@ draw_list_visible(const struct DrawState* state)
const struct PoEntry* current = state->entries +
state->first_shown_msgid-1;
- int max_screen_entries = state->maxy-2;
+ int max_screen_entries = state->maxy-1;
int cy = 0;
size_t i = state->first_shown_msgid;
diff --git a/poe.1.in b/poe.1.in
@@ -65,14 +65,16 @@ box tab(@);
l l.
\fBKey\fP@\fBAction\fP
_
-\fCEscape\fP@Close dialog or clear error
+\fCEsc\fP@Close dialog or clear error
\fCEnter\fP@Edit entry
\fCH\fP or \fCF1\fP@Show help dialog
\fCg\fP or \fCHome\fP@First entry
+\fCC-B\fP or \fCPgUp\fP@Go to previous page
\fCk\fP or \fC\[ua]\fP@Previous entry
\fCj\fP or \fC\[da]\fP@Next entry
+\fCC-F\fP or \fCPgDn\fP@Go to next page
\fCG\fP or \fCEnd\fP@Last entry
-\fCf\fP or \fCC-F\fP@Toggle fuzzy flag
+\fCf\fP or \fCC-Z\fP@Toggle fuzzy flag
\fCq\fP or \fCC-Q\fP@Quit
.TE
.
@@ -87,10 +89,10 @@ l l.
\fBKey\fR@\fBAction\fR
_
\fCC-S\fR@Update entry and close dialog
-\fCC-P\fP or \fCPgUp\fP@Update entry and edit previous entry
-\fCC-N\fP or \fCPgDn\fP@Update entry and edit next entry
+\fCC-B\fP or \fCPgUp\fP@Update entry and edit previous entry
+\fCC-F\fP or \fCPgDn\fP@Update entry and edit next entry
\fCEscape\fP@Cancel changes and close dialog
-\fCC-F\fP@Toggle fuzzy flag
+\fCC-Z\fP@Toggle fuzzy flag
\fCC-A\fP or \fCHome\fP@Go to start of line
\fCC-E\fP or \fCEnd\fP@Go to end of line
\fCC-U\fP@Erase to start of line
diff --git a/poe.c b/poe.c
@@ -97,6 +97,12 @@ void move_start(struct DrawState* state);
void move_left(struct DrawState* state);
void move_right(struct DrawState* state);
void move_end(struct DrawState* state);
+void move_list_up(struct DrawState* state);
+void move_list_down(struct DrawState* state);
+void move_list_start(struct DrawState* state);
+void move_list_end(struct DrawState* state);
+void move_list_page_up(struct DrawState* state);
+void move_list_page_down(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);
@@ -312,6 +318,88 @@ move_end(struct DrawState* state)
state->input_first_shown_column = 0;
}
+void
+move_list_up(struct DrawState* state)
+{
+ if (state->msgid_number > 1)
+ {
+ state->error[0] = 0;
+ state->msgid_number--;
+ if (state->msgid_number < state->first_shown_msgid)
+ state->first_shown_msgid--;
+ }
+}
+
+void
+move_list_down(struct DrawState* state)
+{
+ if (state->msgid_number < state->msgid_count)
+ {
+ state->error[0] = 0;
+ state->msgid_number++;
+ if (state->msgid_number - state->first_shown_msgid >
+ state->maxy - 2)
+ state->first_shown_msgid++;
+ }
+}
+
+void
+move_list_start(struct DrawState* state)
+{
+ state->error[0] = 0;
+ state->msgid_number = state->msgid_count > 0 ? 1 : 0;
+ state->first_shown_msgid = state->msgid_number;
+}
+
+void
+move_list_end(struct DrawState* state)
+{
+ state->error[0] = 0;
+ state->msgid_number = state->msgid_count;
+ state->first_shown_msgid = state->msgid_count > 0 ?
+ state->msgid_number - (state->maxy - 2) : 0;
+}
+
+void
+move_list_page_up(struct DrawState* state)
+{
+ state->error[0] = 0;
+ if (state->msgid_number > state->maxy - 2)
+ {
+ state->msgid_number -= state->maxy - 2;
+ if (state->msgid_number < state->first_shown_msgid)
+ state->first_shown_msgid = state->msgid_number;
+ }
+ else
+ move_list_start(state);
+}
+
+void
+move_list_page_down(struct DrawState* state)
+{
+ state->error[0] = 0;
+ if (state->msgid_number < state->msgid_count - state->maxy - 2)
+ {
+ state->msgid_number += state->maxy - 2;
+ if (state->msgid_number - state->first_shown_msgid >
+ state->maxy - 2)
+ state->first_shown_msgid = state->msgid_number -
+ (state->maxy - 2);
+ }
+ else
+ move_list_end(state);
+}
+
+void
+toggle_fuzzy(struct DrawState* state)
+{
+ if (state->msgid_count > 0)
+ {
+ state->entries[state->msgid_number-1].flags ^= FL_FUZZY;
+ state->dirty = 1;
+ }
+}
+
/* Calculates display length of an input buffer line.
* max_index = the input index up to which the length is calculated
*/
@@ -495,7 +583,6 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
if (state->msgid_count < 1)
return;
- struct PoEntry* entry = &state->entries[state->msgid_number-1];
struct BufferLine* buffer_line = &state->input_buffer[state->input_row];
if (state->error[0])
@@ -545,11 +632,6 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
if (!join_lines(state, state->input_row-1))
strcpy(state->error, errors[ERR_CANT_ALLOC]);
}
- else if (ev->key == TB_KEY_CTRL_F)
- {
- entry->flags ^= FL_FUZZY;
- state->dirty = 1;
- }
else if (ev->key == TB_KEY_CTRL_Q)
strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]);
else if (ev->key == TB_KEY_CTRL_S)
@@ -562,6 +644,8 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
erase_to_start(state);
else if (ev->key == TB_KEY_CTRL_K)
erase_to_end(state);
+ else if (ev->key == TB_KEY_CTRL_Z)
+ toggle_fuzzy(state);
else if (ev->key == TB_KEY_DELETE)
{
if (buffer_line->text[state->input_column])
@@ -597,11 +681,10 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
|| ev->key == TB_KEY_CTRL_A)
move_start(state);
else if (ev->key == TB_KEY_PGDN
- || ev->key == TB_KEY_CTRL_N)
+ || ev->key == TB_KEY_CTRL_F)
{
save_msgstr(state);
- if (state->msgid_number != state->msgid_count)
- state->msgid_number++;
+ move_list_down(state);
load_msgstr(state, 0);
state->input_row = 0;
state->input_first_shown_row = 0;
@@ -609,11 +692,10 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
state->error[0] = 0;
}
else if (ev->key == TB_KEY_PGUP
- || ev->key == TB_KEY_CTRL_P)
+ || ev->key == TB_KEY_CTRL_B)
{
save_msgstr(state);
- if (state->msgid_number > 1)
- state->msgid_number--;
+ move_list_up(state);
load_msgstr(state, 0);
state->input_row = 0;
state->input_first_shown_row = 0;
@@ -673,12 +755,22 @@ handle_key_event(struct tb_event* ev, struct DrawState* state)
}
else if (state->show_help)
strcpy(state->error, errors[ERR_DLG_OPEN]);
- else if (ev->key == TB_KEY_F1
- || ev->ch == 'H')
- {
- state->show_help = 1;
- state->error[0] = 0;
- }
+ else if (ev->key == TB_KEY_ARROW_DOWN
+ || ev->ch == 'j')
+ move_list_down(state);
+ else if (ev->key == TB_KEY_ARROW_UP
+ || ev->ch == 'k')
+ move_list_up(state);
+ else if (ev->key == TB_KEY_CTRL_B || ev->key == TB_KEY_PGUP)
+ move_list_page_up(state);
+ else if (ev->key == TB_KEY_CTRL_F || ev->key == TB_KEY_PGDN)
+ move_list_page_down(state);
+ else if (ev->key == TB_KEY_CTRL_Z
+ || (ev->ch == 'f' && !state->show_edit))
+ toggle_fuzzy(state);
+ else if (ev->key == TB_KEY_END
+ || ev->ch == 'G')
+ move_list_end(state);
else if (ev->key == TB_KEY_ENTER)
{
if (state->msgid_count == 0)
@@ -697,44 +789,14 @@ handle_key_event(struct tb_event* ev, struct DrawState* state)
strcpy(state->error, errors[ERR_CANT_ALLOC]);
}
}
- else if (ev->key == TB_KEY_CTRL_F
- || (ev->ch == 'f' && !state->show_edit))
- {
- if (state->msgid_count > 0)
- {
- state->entries[state->msgid_number-1].flags ^= FL_FUZZY;
- state->dirty = 1;
- }
- }
- else if (ev->key == TB_KEY_HOME || ev->ch == 'g')
- {
- state->error[0] = 0;
- state->msgid_number = state->msgid_count > 0 ? 1 : 0;
- }
- else if (ev->key == TB_KEY_ARROW_UP
- || ev->ch == 'k')
- {
- if (state->msgid_number > 1)
- {
- state->error[0] = 0;
- state->msgid_number--;
- }
- }
- else if (ev->key == TB_KEY_ARROW_DOWN
- || ev->ch == 'j')
- {
- if (state->msgid_number < state->msgid_count)
- {
- state->error[0] = 0;
- state->msgid_number++;
- }
- }
- else if (ev->key == TB_KEY_END
- || ev->ch == 'G')
+ else if (ev->key == TB_KEY_F1
+ || ev->ch == 'H')
{
+ state->show_help = 1;
state->error[0] = 0;
- state->msgid_number = state->msgid_count;
}
+ else if (ev->key == TB_KEY_HOME || ev->ch == 'g')
+ move_list_start(state);
else
strcpy(state->error, errors[ERR_UNKNOWN_KEY]);
}
@@ -864,8 +926,6 @@ main(int argc, char** argv)
tb_clear();
state.maxx = tb_width();
state.maxy = tb_height();
- if (state.msgid_number - state.first_shown_msgid > state.maxx-2)
- state.first_shown_msgid = state.msgid_number;
if (!draw(&state))
strcpy(state.error, errors[ERR_CANT_ALLOC]);