| 238 |
// Get accurate offset of first character of CJK at offset position |
// Get accurate offset of first character of CJK at offset position |
| 239 |
for (i = 0; i < offset; i++) |
for (i = 0; i < offset; i++) |
| 240 |
{ |
{ |
| 241 |
if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK |
if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK |
| 242 |
{ |
{ |
| 243 |
i++; |
i++; |
| 244 |
} |
} |
| 435 |
return 0; |
return 0; |
| 436 |
} |
} |
| 437 |
|
|
| 438 |
int editor_data_delete(EDITOR_DATA *p_editor_data, long display_line, long offset, |
int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset, |
| 439 |
long *p_last_updated_line) |
long *p_last_updated_line) |
| 440 |
{ |
{ |
| 441 |
|
long display_line = *p_display_line; |
| 442 |
|
long offset = *p_offset; |
| 443 |
char *p_data_line = NULL; |
char *p_data_line = NULL; |
| 444 |
long len_data_line; |
long len_data_line; |
| 445 |
long offset_data_line; |
long offset_data_line; |
| 458 |
// Get accurate offset of first character of CJK at offset position |
// Get accurate offset of first character of CJK at offset position |
| 459 |
for (i = 0; i < offset; i++) |
for (i = 0; i < offset; i++) |
| 460 |
{ |
{ |
| 461 |
if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK |
if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK |
| 462 |
{ |
{ |
| 463 |
i++; |
i++; |
| 464 |
} |
} |
| 506 |
{ |
{ |
| 507 |
str_len = 1; |
str_len = 1; |
| 508 |
} |
} |
| 509 |
else if (p_data_line[offset_data_line + 1] < 0 || p_data_line[offset_data_line] > 127) // GBK |
else if (p_data_line[offset_data_line + 1] < 0) // GBK |
| 510 |
{ |
{ |
| 511 |
str_len = 2; |
str_len = 2; |
| 512 |
} |
} |
| 597 |
*p_last_updated_line = MAX(j - 1, *p_last_updated_line); |
*p_last_updated_line = MAX(j - 1, *p_last_updated_line); |
| 598 |
} |
} |
| 599 |
|
|
| 600 |
|
// Return real offset |
| 601 |
|
*p_offset = offset; |
| 602 |
|
|
| 603 |
return str_len; |
return str_len; |
| 604 |
} |
} |
| 605 |
|
|
| 720 |
|
|
| 721 |
if (!key_insert) // overwrite |
if (!key_insert) // overwrite |
| 722 |
{ |
{ |
| 723 |
if (editor_data_delete(p_editor_data, display_line_in, offset_in, |
if (editor_data_delete(p_editor_data, &display_line_out, &offset_out, |
| 724 |
&last_updated_line) < 0) |
&last_updated_line) < 0) |
| 725 |
{ |
{ |
| 726 |
log_error("editor_data_delete() error\n"); |
log_error("editor_data_delete() error\n"); |
| 761 |
{ |
{ |
| 762 |
row_pos += (display_line_out - display_line_in); |
row_pos += (display_line_out - display_line_in); |
| 763 |
} |
} |
| 764 |
col_pos = offset_out + 1; |
col_pos = offset_out + 1; // Set col_pos to accurate pos |
| 765 |
} |
} |
| 766 |
|
|
| 767 |
str_len = 0; |
str_len = 0; |
| 778 |
} |
} |
| 779 |
|
|
| 780 |
col_pos--; |
col_pos--; |
| 781 |
|
if (col_pos > 1 && |
| 782 |
|
p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 1] < 0) // GBK |
| 783 |
|
{ |
| 784 |
|
col_pos--; |
| 785 |
|
} |
| 786 |
|
|
| 787 |
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
| 788 |
{ |
{ |
| 789 |
row_pos--; |
row_pos--; |
| 791 |
} |
} |
| 792 |
} |
} |
| 793 |
|
|
| 794 |
if ((str_len = editor_data_delete(p_editor_data, line_current - output_current_row + row_pos, col_pos - 1, |
display_line_in = line_current - output_current_row + row_pos; |
| 795 |
|
offset_in = col_pos - 1; |
| 796 |
|
display_line_out = display_line_in; |
| 797 |
|
offset_out = offset_in; |
| 798 |
|
|
| 799 |
|
if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out, |
| 800 |
&last_updated_line)) < 0) |
&last_updated_line)) < 0) |
| 801 |
{ |
{ |
| 802 |
log_error("editor_data_delete() error\n"); |
log_error("editor_data_delete() error\n"); |
| 803 |
} |
} |
| 804 |
else |
else |
| 805 |
{ |
{ |
| 806 |
if (ch == BACKSPACE) |
col_pos = offset_out + 1; // Set col_pos to accurate pos |
|
{ |
|
|
for (i = 1; i < str_len; i++) |
|
|
{ |
|
|
col_pos--; |
|
|
if (col_pos < 1 && line_current - output_current_row + row_pos >= 0) |
|
|
{ |
|
|
row_pos--; |
|
|
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]); |
|
|
} |
|
|
} |
|
|
} |
|
| 807 |
|
|
| 808 |
output_end_row = MIN(SCREEN_ROWS - 1, output_current_row + (int)(last_updated_line - line_current)); |
output_end_row = MIN(SCREEN_ROWS - 1, output_current_row + (int)(last_updated_line - line_current)); |
| 809 |
line_current -= (output_current_row - row_pos); |
line_current -= (output_current_row - row_pos); |
| 850 |
break; |
break; |
| 851 |
case Ctrl('E'): // End of line |
case Ctrl('E'): // End of line |
| 852 |
case KEY_CTRL_RIGHT: |
case KEY_CTRL_RIGHT: |
| 853 |
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
if (line_current - output_current_row + row_pos == p_editor_data->display_line_total - 1) // row_pos at end line |
| 854 |
{ |
{ |
| 855 |
// last display line does NOT have \n in the end |
// last display line does NOT have \n in the end |
| 856 |
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
| 916 |
if (col_pos > 1) |
if (col_pos > 1) |
| 917 |
{ |
{ |
| 918 |
col_pos--; |
col_pos--; |
| 919 |
|
if (col_pos > 1 && |
| 920 |
|
p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 1] < 0 && |
| 921 |
|
p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 2] < 0) // GBK |
| 922 |
|
{ |
| 923 |
|
col_pos--; |
| 924 |
|
} |
| 925 |
break; |
break; |
| 926 |
} |
} |
| 927 |
col_pos = SCREEN_COLS; // continue to KEY_UP |
col_pos = SCREEN_COLS; // continue to KEY_UP |
| 949 |
case KEY_RIGHT: |
case KEY_RIGHT: |
| 950 |
if (col_pos < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]) |
if (col_pos < p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]) |
| 951 |
{ |
{ |
| 952 |
|
if (p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos - 1] < 0 && |
| 953 |
|
p_editor_data->p_display_lines[line_current - output_current_row + row_pos][col_pos] < 0) // GBK |
| 954 |
|
{ |
| 955 |
|
col_pos++; |
| 956 |
|
} |
| 957 |
col_pos++; |
col_pos++; |
| 958 |
break; |
break; |
| 959 |
} |
} |
| 965 |
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])); |
col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos])); |
| 966 |
break; |
break; |
| 967 |
} |
} |
| 968 |
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
if (line_current - output_current_row + row_pos == p_editor_data->display_line_total - 1) // row_pos at end line |
| 969 |
{ |
{ |
| 970 |
// last display line does NOT have \n in the end |
// last display line does NOT have \n in the end |
| 971 |
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |