| 79 |
{ |
{ |
| 80 |
EDITOR_DATA *p_editor_data; |
EDITOR_DATA *p_editor_data; |
| 81 |
char *p_data_line = NULL; |
char *p_data_line = NULL; |
| 82 |
long line_offsets[MAX_EDITOR_DATA_LINES]; |
long line_offsets[MAX_EDITOR_DATA_LINES + 1]; |
| 83 |
long current_data_line_length = 0; |
long current_data_line_length = 0; |
| 84 |
long i; |
long i; |
| 85 |
|
|
| 96 |
return NULL; |
return NULL; |
| 97 |
} |
} |
| 98 |
|
|
| 99 |
p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES); |
p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES + 1); |
| 100 |
|
|
| 101 |
for (i = 0; i < p_editor_data->display_line_total; i++) |
for (i = 0; i < p_editor_data->display_line_total; i++) |
| 102 |
{ |
{ |
| 417 |
*p_offset -= p_editor_data->display_line_lengths[*p_display_line]; |
*p_offset -= p_editor_data->display_line_lengths[*p_display_line]; |
| 418 |
(*p_display_line)++; |
(*p_display_line)++; |
| 419 |
} |
} |
| 420 |
else if (*p_display_line + 1 >= MAX_EDITOR_DATA_LINES) |
} |
| 421 |
|
|
| 422 |
|
// Prevent the last display line from being over-length |
| 423 |
|
if (p_editor_data->display_line_total == MAX_EDITOR_DATA_LINES) |
| 424 |
|
{ |
| 425 |
|
len = split_line(p_editor_data->p_display_lines[p_editor_data->display_line_total - 1], SCREEN_COLS - 1, &eol, &display_len); |
| 426 |
|
p_editor_data->p_display_lines[p_editor_data->display_line_total - 1][len] = '\0'; |
| 427 |
|
p_editor_data->display_line_lengths[p_editor_data->display_line_total - 1] = len; |
| 428 |
|
if (*p_display_line + 1 >= p_editor_data->display_line_total) |
| 429 |
{ |
{ |
| 430 |
len = split_line(p_editor_data->p_display_lines[*p_display_line], SCREEN_COLS - 1, &eol, &display_len); |
*p_offset = MIN(*p_offset, len); |
| 431 |
p_editor_data->p_display_lines[*p_display_line][len] = '\0'; |
*p_display_line = p_editor_data->display_line_total - 1; |
|
p_editor_data->display_line_lengths[*p_display_line] = len; |
|
|
*p_offset = len; |
|
| 432 |
} |
} |
| 433 |
} |
} |
| 434 |
|
|
| 845 |
break; |
break; |
| 846 |
case Ctrl('E'): // End of line |
case Ctrl('E'): // End of line |
| 847 |
case KEY_CTRL_RIGHT: |
case KEY_CTRL_RIGHT: |
| 848 |
|
if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= p_editor_data->display_line_total) // Reach end |
| 849 |
|
{ |
| 850 |
|
// last display line does NOT have \n in the end |
| 851 |
|
col_pos = p_editor_data->display_line_lengths[line_current - output_current_row + row_pos] + 1; |
| 852 |
|
break; |
| 853 |
|
} |
| 854 |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]); |
col_pos = MAX(1, p_editor_data->display_line_lengths[line_current - output_current_row + row_pos]); |
| 855 |
break; |
break; |
| 856 |
case Ctrl('T'): // Top of screen |
case Ctrl('T'): // Top of screen |