| 425 |
if (offset_data_line + str_len > len_data_line || |
if (offset_data_line + str_len > len_data_line || |
| 426 |
(offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n')) |
(offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n')) |
| 427 |
{ |
{ |
| 428 |
log_error("Nothing to be delete\n"); |
if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line) |
| 429 |
return 0; |
{ |
| 430 |
} |
log_common("Debug: No additional display line: %ld + 1 >= %ld\n", display_line, p_editor_data->display_line_total); |
| 431 |
|
return 0; |
| 432 |
|
} |
| 433 |
|
|
| 434 |
|
len_data_line = 0; // Next data line |
| 435 |
|
last_display_line = p_editor_data->display_line_total - 1; |
| 436 |
|
for (i = display_line + 1; i < p_editor_data->display_line_total; i++) |
| 437 |
|
{ |
| 438 |
|
len_data_line += p_editor_data->display_line_lengths[i]; |
| 439 |
|
|
| 440 |
memmove(p_data_line + offset_data_line, p_data_line + offset_data_line + str_len, (size_t)(len_data_line - offset_data_line - str_len)); |
if (p_editor_data->display_line_lengths[i] > 0 && |
| 441 |
p_data_line[len_data_line - str_len] = '\0'; |
p_editor_data->p_display_lines[i][p_editor_data->display_line_lengths[i] - 1] == '\n') // reach end of current data line |
| 442 |
len_data_line -= str_len; |
{ |
| 443 |
|
last_display_line = i; |
| 444 |
|
break; |
| 445 |
|
} |
| 446 |
|
} |
| 447 |
|
|
| 448 |
|
if (offset_data_line + len_data_line + 1 > MAX_EDITOR_DATA_LINE_LENGTH) // No enough buffer to merge current data line with next data line |
| 449 |
|
{ |
| 450 |
|
log_common("Debug: No enough buffer to merge with next data line: %ld > %ld\n", |
| 451 |
|
offset_data_line + len_data_line + 1, MAX_EDITOR_DATA_LINE_LENGTH); |
| 452 |
|
return 0; |
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
// Append next data line to current one |
| 456 |
|
memcpy(p_data_line + offset_data_line, p_editor_data->p_display_lines[display_line + 1], (size_t)len_data_line); |
| 457 |
|
p_data_line[offset_data_line + len_data_line] = '\0'; |
| 458 |
|
|
| 459 |
|
// Recycle next data line |
| 460 |
|
// TODO: free(p_editor_data->p_display_lines[display_line + 1]); |
| 461 |
|
} |
| 462 |
|
else |
| 463 |
|
{ |
| 464 |
|
memmove(p_data_line + offset_data_line, p_data_line + offset_data_line + str_len, (size_t)(len_data_line - offset_data_line - str_len)); |
| 465 |
|
p_data_line[len_data_line - str_len] = '\0'; |
| 466 |
|
len_data_line -= str_len; |
| 467 |
|
} |
| 468 |
|
|
| 469 |
// Set p_data_line to head of current display line |
// Set p_data_line to head of current display line |
| 470 |
p_data_line = p_editor_data->p_display_lines[display_line]; |
p_data_line = p_editor_data->p_display_lines[display_line]; |
| 505 |
*p_last_updated_line = p_editor_data->display_line_total - 1; |
*p_last_updated_line = p_editor_data->display_line_total - 1; |
| 506 |
} |
} |
| 507 |
|
|
| 508 |
return 0; |
return str_len; |
| 509 |
} |
} |
| 510 |
|
|
| 511 |
static int editor_display_key_handler(int *p_key, EDITOR_CTX *p_ctx) |
static int editor_display_key_handler(int *p_key, EDITOR_CTX *p_ctx) |
| 672 |
continue; |
continue; |
| 673 |
} |
} |
| 674 |
} |
} |
| 675 |
else if (ch == KEY_DEL) // Del |
else if (ch == KEY_DEL || ch == BACKSPACE) // Del |
| 676 |
{ |
{ |
| 677 |
last_updated_line = line_current; |
if (ch == BACKSPACE) |
| 678 |
|
{ |
| 679 |
|
col_pos--; |
| 680 |
|
if (col_pos < 1 && line_current - screen_current_row + row_pos >= 0) |
| 681 |
|
{ |
| 682 |
|
row_pos--; |
| 683 |
|
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]); |
| 684 |
|
} |
| 685 |
|
} |
| 686 |
|
|
| 687 |
if (editor_data_delete(p_editor_data, line_current - screen_current_row + row_pos, col_pos - 1, |
if ((str_len = editor_data_delete(p_editor_data, line_current - screen_current_row + row_pos, col_pos - 1, |
| 688 |
&last_updated_line) < 0) |
&last_updated_line)) < 0) |
| 689 |
{ |
{ |
| 690 |
log_error("editor_data_delete() error\n"); |
log_error("editor_data_delete() error\n"); |
| 691 |
} |
} |
| 692 |
else |
else |
| 693 |
{ |
{ |
| 694 |
|
if (ch == BACKSPACE) |
| 695 |
|
{ |
| 696 |
|
for (i = 1; i < str_len; i++) |
| 697 |
|
{ |
| 698 |
|
col_pos--; |
| 699 |
|
if (col_pos < 1 && line_current - screen_current_row + row_pos >= 0) |
| 700 |
|
{ |
| 701 |
|
row_pos--; |
| 702 |
|
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos]); |
| 703 |
|
} |
| 704 |
|
} |
| 705 |
|
} |
| 706 |
|
|
| 707 |
screen_end_row = MIN(SCREEN_ROWS - 1, screen_current_row + (int)(last_updated_line - line_current)); |
screen_end_row = MIN(SCREEN_ROWS - 1, screen_current_row + (int)(last_updated_line - line_current)); |
| 708 |
line_current -= (screen_current_row - row_pos); |
line_current -= (screen_current_row - row_pos); |
| 709 |
screen_current_row = (int)row_pos; |
screen_current_row = (int)row_pos; |
| 710 |
|
|
| 711 |
|
if (screen_current_row < screen_begin_row) // row_pos <= 0 |
| 712 |
|
{ |
| 713 |
|
screen_current_row = screen_begin_row; |
| 714 |
|
row_pos = screen_begin_row; |
| 715 |
|
screen_end_row = SCREEN_ROWS - 1; |
| 716 |
|
} |
| 717 |
} |
} |
| 718 |
|
|
| 719 |
continue; |
continue; |