| 223 | |
| 224 | |
| 225 | static CopyEntry *copy_line(TextEditorState *state, int line_number) { |
| 226 | if (state->copy_reset) { |
| 227 | state->copy_reset = 0; |
| 228 | state->n_copied_lines = 0; |
| 229 | } |
| 230 | |
| 231 | // Get current line |
| 232 | int line_start = state->offset_list[line_number]; |
| 233 | char line[MAX_LINE_CHARACTERS]; |
| 234 | int length = textReadLine(state->buffer, line_start, state->size, line); |
| 235 | |
| 236 | CopyEntry *entry = &state->copy_buffer[state->n_copied_lines]; |
| 237 | |
| 238 | // Copy line into copy_buffer |
| 239 | memcpy(entry->line, &state->buffer[line_start], length); |
| 240 | |
| 241 | // Make sure line end with a newline |
| 242 | if (entry->line[length - 1] != '\n') { |
| 243 | entry->line[length] = '\n'; |
| 244 | length++; |
| 245 | } |
| 246 | |
| 247 | // Terminate line |
| 248 | state->copy_buffer[state->n_copied_lines].line[length] = '\0'; |
| 249 | |
| 250 | state->n_copied_lines++; |
| 251 | |
| 252 | return entry; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | static void delete_line(TextEditorState *state, int line_number) { |
no test coverage detected