sled

Једноставни уређивач текста
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 99f581a62d270044e8ba9fb6791fb680a22f0b97
родитељ 6ea2dd3f75174c680d0eaf08792222f2d823faea
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Tue, 22 Feb 2022 23:28:34 +0100

WIP copy/paste continued

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

Diffstat:
MTODO | 4+++-
Apaste_selection | 42++++++++++++++++++++++++++++++++++++++++++
Msled.c | 52+++++++++++++++++++++++++++++++++++++++++-----------
измењених датотека: 3, додавања: 86(+), брисања: 12(-)

diff --git a/TODO b/TODO @@ -1,7 +1,9 @@ TODO ==== - [ ] Copy/paste? + [x] Copy/paste? + + [ ] Investigate DrawState.first_shown_column [ ] Add vi V diff --git a/paste_selection b/paste_selection @@ -0,0 +1,42 @@ + + + + 0 one + 1 two + 2 three <-- rows_count = 3 + + + |line... + foo blurfle| <-- paste_count = 2 + + + 0 oneline... <-- state->row == 0 + 1 foo blurfletwo column == 3 + 2 three <-- rows_count - state->row - state->paste_count - 1 == + == 3 - 0 - 2 - 1 = 0 + + |line... + another line + foo blurfle| <-- paste_count == 3 + + 0 one + 1 two + 2 three <-- row == 2 + 3 four + 4 five + 5 six + 6 seven + 7 eight <-- rows_count == 8 + + rows_count - row - paste_count + 1 == 8 - 0 - 3 + 1 == 6 + + 0 one row = 6..1 + 1 two + 2 threeline... 2 + 3 - 2 + row + 3 another line == 2 + 3 - 2 + 6 == 9 + 4 foo blurflefour + 5 five 2 + 3 - 2 + row - 1 + 6 six == 2 + 3 - 2 + 6 - 1 == 8 + 7 seven + 8 eight + diff --git a/sled.c b/sled.c @@ -443,6 +443,8 @@ paste_from_paste(struct DrawState* state) uint32_t* newtext = NULL; struct BufferLine* line = NULL; struct BufferLine* newbuf = NULL; + size_t dlen; + uint32_t* rest = NULL; if (!state->paste_count) return 0; @@ -473,18 +475,15 @@ paste_from_paste(struct DrawState* state) } state->buffer = newbuf; } - /* TODO: */ - for (size_t row = 0; row < state->rows_count - state->row; row++) - { - line = state->buffer + state->row + state->paste_count - + row; - line->length = u32_strcpy(line->text, - state->buffer[state->row + row].text); - } } line = state->buffer + state->row; newtext = calloc(MAXBUFLINE, sizeof(uint32_t)); + if (!newtext) + { + strcpy(state->error, errors[ERR_CANT_ALLOC]); + goto paste_from_paste_cleanup; + } u32_strncpy(newtext, line->text, state->column + 1); u32_strcat(newtext, state->paste[0].text); @@ -495,6 +494,25 @@ paste_from_paste(struct DrawState* state) } else { + rest = calloc(MAXBUFLINE, sizeof(uint32_t)); + if (!rest) + { + strcpy(state->error, errors[ERR_CANT_ALLOC]); + goto paste_from_paste_cleanup; + } + u32_strcpy(rest, line->text + state->column); + line->length = u32_strcpy(line->text, newtext); + /* TODO: */ + for (size_t row = state->rows_count - state->row + - (state->paste_count - 2) - 1; + row > 0; row--) + { + line = state->buffer + state->row + state->paste_count + - 2 + row - 1; + line->length = u32_strcpy(line->text, + state->buffer[state->row + row - 1].text); + } + line = state->buffer + state->row; line->length = u32_strcpy(line->text, newtext); for (size_t row = 1; row < state->paste_count - 1; row++) { @@ -502,13 +520,11 @@ paste_from_paste(struct DrawState* state) line->length = u32_strcpy(line->text, state->paste[row].text); } - line = state->buffer + state->row + state->paste_count - 1; u32_strcpy(newtext, state->paste[state->paste_count - 1].text); - u32_strcat(newtext, line->text); + u32_strcat(newtext, rest); line->length = u32_strcpy(line->text, newtext); } - free(newtext); /*for (size_t row = state->paste_size - ALLOC_DELTA; row < state->paste_size; row++) { @@ -536,7 +552,21 @@ paste_from_paste(struct DrawState* state) = u32_strncpy(state->paste[state->paste_count - 1].text, state->buffer[ser].text, sec + 1); }*/ + state->row += state->paste_count - 1; + state->column += state->paste[state->paste_count - 1].length; + state->display_column = display_length(state, + state->buffer[state->row].text, state->column); + if (state->first_shown_column > state->display_column) + state->first_shown_column = state->display_column; + if (state->first_shown_column + state->maxx - 1 < state->display_column) + state->first_shown_column + = state->display_column - state->maxx + 1; + state->dirty = 1; + +paste_from_paste_cleanup: + free(rest); + free(newtext); return 0; }