чување 2d4c598721850cd3e21294556d6cc5945254ec80
родитељ 240cbac70f9d365dc08a141e5441ffa7abf7e5f2
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 12 Jul 2021 20:21:42 +0200
Added C-C = yank and C-V = paste
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | TODO | | | 12 | ++++++------ |
| M | draw.c | | | 11 | +++++++++++ |
| M | draw.h | | | 4 | +++- |
| M | poe.1.in | | | 2 | +- |
| M | poe.c | | | 154 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
измењених датотека: 5, додавања: 160(+), брисања: 23(-)
diff --git a/TODO b/TODO
@@ -2,14 +2,14 @@
====
[x] Line editing with cursor
- [x] Previous/next word?
+ <x> Previous/next word?
[x] Enter -> F6 -> Esc -> Enter should not focus info box
- [~] Yank/paste (entire current msgstr)
+ [x] Yank/paste (entire current msgstr)
[x] Copy msgid (only) to msgstr
- [ ] Yank msgstr to paste buffer
- [ ] Paste paste buffer to msgstr
+ [x] Yank msgstr to paste buffer
+ [x] Paste paste buffer to msgstr
[x] Handle #~ (Don't show; flag? But write to file)
@@ -18,13 +18,13 @@
[x] Search highlighting
[x] Go to prev/next match
- [ ] Sort by flag/column?
+ < > Sort by flag/column?
Legend
------
- ? = low priority/maybe
+ < > = low priority/maybe
[ ] = todo
[~] = partially done
[x] = fully done
diff --git a/draw.c b/draw.c
@@ -99,6 +99,8 @@ init_drawstate(struct DrawState* state, char* error, char* filename,
state->info_first_shown_column = 0;
state->info_first_shown_row = 0;
state->info_rows_count = 0;
+ state->paste_buffer = NULL;
+ state->paste_rows_count = 0;
state->search_column = 0;
state->search_first_shown_column = 0;
state->search_display_column = 0;
@@ -141,6 +143,15 @@ free_drawstate(struct DrawState* state)
}
free(state->input_buffer);
}
+ if (state->paste_buffer)
+ {
+ for (i = 0; i < state->paste_rows_count; i++)
+ {
+ current = state->paste_buffer+i;
+ free_bufferline(current);
+ }
+ free(state->paste_buffer);
+ }
if (state->info_buffer)
{
for (i = 0; i < state->info_rows_count; i++)
diff --git a/draw.h b/draw.h
@@ -52,12 +52,14 @@ struct DrawState {
int input_display_column;
FlagChange input_changed_fuzzy;
int saved_column;
- struct BufferLine* info_buffer; /* information pane above
+ struct BufferLine* info_buffer; /* information pane above
* edit box */
int info_first_shown_column;
int info_first_shown_row;
int info_rows_count;
int info_rows_maxlen;
+ struct BufferLine* paste_buffer;
+ int paste_rows_count;
int search_column;
int search_first_shown_column;
int search_display_column;
diff --git a/poe.1.in b/poe.1.in
@@ -126,7 +126,7 @@ _
.LP
In the table above, "current msgstr" refers to the situation when there are
multiple msgstrs, representing different plural forms. Only the currently shown
-msgstr is affected.
+plural form is affected.
.
.LP
When the info box is focused, arrow keys, \fCC-B\fP/\fCC-F\fP
diff --git a/poe.c b/poe.c
@@ -49,6 +49,8 @@ void move_search_prev_word(struct DrawState* state);
void move_search_next_word(struct DrawState* state);
void erase_search_prev_word(struct DrawState* state);
struct DrawState* copy_msgid_to_input(struct DrawState* state);
+struct DrawState* yank_msgstr_to_paste_buffer(struct DrawState* state);
+struct DrawState* paste_paste_buffer_to_input(struct DrawState* state);
void next_match(struct DrawState* state);
void prev_match(struct DrawState* state);
void next_untranslated(struct DrawState* state);
@@ -783,25 +785,26 @@ erase_search_prev_word(struct DrawState* state)
struct DrawState*
copy_msgid_to_input(struct DrawState* state)
{
+ if (state->edit_info_focused)
+ return state;
+
if (state->msgid_number == 1)
{
strcpy(state->error, errors[ERR_ILLEGAL_ON_FIRST]);
return NULL;
}
- if (state->edit_info_focused)
- return state;
+
struct PoEntry* current = &state->entries[state->msgid_number-1];
- size_t msgid_num_lines = u32_lines_in_string(current->msgid, NULL);
- size_t lines_to_init = state->input_rows_count < msgid_num_lines
+ size_t msgid_num_lines = u32_lines_in_string(current->msgid, NULL);
+ size_t lines_to_init = state->input_rows_count < msgid_num_lines
? msgid_num_lines - state->input_rows_count : 0;
- size_t lines_to_free = state->input_rows_count > msgid_num_lines
+ size_t lines_to_free = state->input_rows_count > msgid_num_lines
? state->input_rows_count - msgid_num_lines : 0;
for (size_t i = 0; i < lines_to_free; i++)
free_bufferline(state->input_buffer+
state->input_rows_count-i-1);
- struct BufferLine* newbuf = realloc(
- state->input_buffer, msgid_num_lines *
- sizeof(struct BufferLine));
+ struct BufferLine* newbuf = realloc(state->input_buffer,
+ msgid_num_lines * sizeof(struct BufferLine));
uint32_t* pmsgid = current->msgid;
if (!newbuf)
@@ -821,19 +824,136 @@ copy_msgid_to_input(struct DrawState* state)
if (pmsgid)
for (size_t i = 0; i < msgid_num_lines; i++)
{
- pbuffer = newbuf+i;
- size_t len = u32_line_length(pmsgid);
+ pbuffer = newbuf+i;
+ size_t len = u32_line_length(pmsgid);
size_t newlen = 0;
u32_strncpy(pbuffer->text, pmsgid, MIN(len+1,
MAXBUFLINE));
- newlen = u32_decode_tabs(pbuffer->text, MAXBUFLINE);
- pbuffer->length = newlen;
- pmsgid += len+(pmsgid[len] ? 2 : 0);
+ newlen = u32_decode_tabs(pbuffer->text,
+ MAXBUFLINE);
+ pbuffer->length = newlen;
+ pmsgid += len+(pmsgid[len] ? 2 : 0);
}
state->input_rows_count = msgid_num_lines;
- state->input_buffer = newbuf;
- state->dirty = 1;
+ state->input_buffer = newbuf;
+ state->dirty = 1;
+
+ return state;
+}
+
+struct DrawState*
+yank_msgstr_to_paste_buffer(struct DrawState* state)
+{
+ if (state->edit_info_focused)
+ return state;
+
+ if (state->msgid_number == 1)
+ {
+ strcpy(state->error, errors[ERR_ILLEGAL_ON_FIRST]);
+ return NULL;
+ }
+
+ struct PoEntry* current = &state->entries[state->msgid_number-1];
+ size_t msgstr_num_lines = u32_lines_in_string(*(current->msgstr +
+ state->msgstr_index), NULL);
+ size_t lines_to_init = state->paste_rows_count < msgstr_num_lines
+ ? msgstr_num_lines - state->paste_rows_count : 0;
+ size_t lines_to_free = state->paste_rows_count > msgstr_num_lines
+ ? state->paste_rows_count - msgstr_num_lines : 0;
+ for (size_t i = 0; i < lines_to_free; i++)
+ free_bufferline(state->paste_buffer+
+ state->paste_rows_count-i-1);
+ struct BufferLine* newbuf = realloc(state->paste_buffer,
+ msgstr_num_lines * sizeof(struct BufferLine));
+ uint32_t* pmsgstr = *(current->msgstr+state->msgstr_index);
+
+ if (!newbuf)
+ return NULL;
+
+ struct BufferLine* pbuffer = NULL;
+ for (size_t i = 0; i < lines_to_init; i++)
+ {
+ pbuffer = newbuf+msgstr_num_lines-1-i;
+ init_bufferline(pbuffer);
+ uint32_t* newtext = calloc(MAXBUFLINE, sizeof(uint32_t));
+ if (!newtext)
+ return NULL;
+ pbuffer->text = newtext;
+ }
+
+ if (pmsgstr)
+ for (size_t i = 0; i < msgstr_num_lines; i++)
+ {
+ pbuffer = newbuf+i;
+ size_t len = u32_line_length(pmsgstr);
+ size_t newlen = 0;
+ u32_strncpy(pbuffer->text, pmsgstr, MIN(len+1,
+ MAXBUFLINE));
+ newlen = u32_decode_tabs(pbuffer->text,
+ MAXBUFLINE);
+ pbuffer->length = newlen;
+ pmsgstr += len+(pmsgstr[len] ? 2 : 0);
+ }
+
+ state->paste_rows_count = msgstr_num_lines;
+ state->paste_buffer = newbuf;
+
+ return state;
+}
+
+struct DrawState*
+paste_paste_buffer_to_input(struct DrawState* state)
+{
+ if (state->edit_info_focused)
+ return state;
+
+ if (state->msgid_number == 1)
+ {
+ strcpy(state->error, errors[ERR_ILLEGAL_ON_FIRST]);
+ return NULL;
+ }
+
+ size_t lines_to_init = state->input_rows_count <
+ state->paste_rows_count ? state->paste_rows_count -
+ state->input_rows_count : 0;
+ size_t lines_to_free = state->input_rows_count >
+ state->paste_rows_count ? state->input_rows_count -
+ state->paste_rows_count: 0;
+ for (size_t i = 0; i < lines_to_free; i++)
+ free_bufferline(state->input_buffer+
+ state->input_rows_count-i-1);
+ struct BufferLine* newbuf = realloc(state->input_buffer,
+ state->paste_rows_count * sizeof(struct BufferLine));
+ struct BufferLine* ppaste = state->paste_buffer;
+
+ if (!newbuf)
+ return NULL;
+
+ struct BufferLine* pinput = NULL;
+ for (size_t i = 0; i < lines_to_init; i++)
+ {
+ pinput = newbuf+state->paste_rows_count-1-i;
+ init_bufferline(pinput);
+ uint32_t* newtext = calloc(MAXBUFLINE, sizeof(uint32_t));
+ if (!newtext)
+ return NULL;
+ pinput->text = newtext;
+ }
+
+ if (ppaste)
+ for (size_t i = 0; i < state->paste_rows_count; i++)
+ {
+ pinput = newbuf+i;
+ u32_strncpy(pinput->text, ppaste->text,
+ MIN(ppaste->length+1, MAXBUFLINE));
+ pinput->length = ppaste->length;
+ ppaste++;
+ }
+
+ state->input_rows_count = state->paste_rows_count;
+ state->input_buffer = newbuf;
+ state->dirty = 1;
return state;
}
@@ -1696,6 +1816,8 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
|| ev->key == TB_KEY_BACKSPACE2)
&& !state->edit_info_focused)
erase_backwards(state);
+ else if (ev->key == TB_KEY_CTRL_C)
+ yank_msgstr_to_paste_buffer(state);
else if (ev->key == TB_KEY_CTRL_K)
erase_to_end(state);
else if (ev->key == TB_KEY_CTRL_N)
@@ -1712,6 +1834,8 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
move_next_word(state);
else if (ev->key == TB_KEY_CTRL_U)
erase_to_start(state);
+ else if (ev->key == TB_KEY_CTRL_V)
+ paste_paste_buffer_to_input(state);
else if (ev->key == TB_KEY_CTRL_W)
erase_prev_word(state);
else if (ev->key == TB_KEY_CTRL_Z)