From fdeaec766f5063b13f61a241b6cc3315f7b06961 Mon Sep 17 00:00:00 2001
From: Egmont Koblinger <egmont@gmail.com>
Date: Sat, 4 Oct 2014 15:23:13 +0200
Subject: [PATCH 2/2] 3250c12
---
src/viewer/ascii.c | 54 +++++++++++++++++++++++++++++++++++++++++++--------
src/viewer/internal.h | 2 ++
src/viewer/move.c | 45 ++++--------------------------------------
3 files changed, 52 insertions(+), 49 deletions(-)
diff --git a/src/viewer/ascii.c b/src/viewer/ascii.c
index e7ebc7d..33efef3 100644
a
|
b
|
mcview_next_combining_char_sequence (mcview_t * view, mcview_state_machine_t * s |
551 | 551 | * @param row print to this row |
552 | 552 | * @param paragraph_ended store TRUE if paragraph ended by newline or EOF, FALSE if wraps to next |
553 | 553 | * line |
| 554 | * @param linewidth store the width of the line here |
554 | 555 | * @return the number of rows, that is, 0 if we were already at EOF, otherwise 1 |
555 | 556 | */ |
556 | 557 | static int |
557 | 558 | mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, |
558 | | gboolean * paragraph_ended) |
| 559 | gboolean * paragraph_ended, off_t * linewidth) |
559 | 560 | { |
560 | 561 | const screen_dimen left = view->data_area.left; |
561 | 562 | const screen_dimen top = view->data_area.top; |
… |
… |
mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, |
570 | 571 | if (paragraph_ended != NULL) |
571 | 572 | *paragraph_ended = TRUE; |
572 | 573 | |
573 | | if (!view->text_wrap_mode && (row < 0 || row >= (int) height)) |
| 574 | if (!view->text_wrap_mode && (row < 0 || row >= (int) height) && linewidth == NULL) |
574 | 575 | { |
575 | 576 | /* Optimization: Fast forward to the end of the line, rather than carefully |
576 | 577 | * parsing and then not actually displaying it. */ |
… |
… |
mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, |
594 | 595 | state_saved = *state; |
595 | 596 | n = mcview_next_combining_char_sequence (view, state, cs, 1 + MAX_COMBINING_CHARS, &color); |
596 | 597 | if (n == 0) |
| 598 | { |
| 599 | if (linewidth != NULL) |
| 600 | *linewidth = col; |
597 | 601 | return (col > 0) ? 1 : 0; |
| 602 | } |
598 | 603 | |
599 | 604 | if (view->search_start <= state->offset && state->offset < view->search_end) |
600 | 605 | color = SELECTED_COLOR; |
… |
… |
mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, |
603 | 608 | { |
604 | 609 | /* New line: reset all formatting state for the next paragraph. */ |
605 | 610 | mcview_state_machine_init (state, state->offset); |
| 611 | if (linewidth != NULL) |
| 612 | *linewidth = col; |
606 | 613 | return 1; |
607 | 614 | } |
608 | 615 | |
… |
… |
mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, |
638 | 645 | *state = state_saved; |
639 | 646 | if (paragraph_ended != NULL) |
640 | 647 | *paragraph_ended = FALSE; |
| 648 | if (linewidth != NULL) |
| 649 | *linewidth = col; |
641 | 650 | return 1; |
642 | 651 | } |
643 | 652 | |
… |
… |
mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, |
699 | 708 | col += charwidth; |
700 | 709 | state->unwrapped_column += charwidth; |
701 | 710 | |
702 | | if (!view->text_wrap_mode && col >= dpy_text_column + width) |
| 711 | if (!view->text_wrap_mode && col >= dpy_text_column + width && linewidth == NULL) |
703 | 712 | { |
704 | 713 | /* Optimization: Fast forward to the end of the line, rather than carefully |
705 | 714 | * parsing and then not actually displaying it. */ |
… |
… |
mcview_display_paragraph (mcview_t * view, mcview_state_machine_t * state, int r |
748 | 757 | { |
749 | 758 | gboolean paragraph_ended; |
750 | 759 | |
751 | | lines += mcview_display_line (view, state, row, ¶graph_ended); |
| 760 | lines += mcview_display_line (view, state, row, ¶graph_ended, NULL); |
752 | 761 | if (paragraph_ended) |
753 | 762 | return lines; |
754 | 763 | |
… |
… |
mcview_wrap_fixup (mcview_t * view) |
793 | 802 | gboolean paragraph_ended; |
794 | 803 | |
795 | 804 | state_prev = view->dpy_state_top; |
796 | | if (mcview_display_line (view, &view->dpy_state_top, -1, ¶graph_ended) == 0) |
| 805 | if (mcview_display_line (view, &view->dpy_state_top, -1, ¶graph_ended, NULL) == 0) |
797 | 806 | break; |
798 | 807 | if (paragraph_ended) |
799 | 808 | { |
… |
… |
mcview_ascii_move_down (mcview_t * view, off_t lines) |
903 | 912 | /* See if there's still data below the bottom line, by imaginarily displaying one |
904 | 913 | * more line. This takes care of reading more data into growbuf, if required. |
905 | 914 | * If the end position didn't advance, we're at EOF and hence bail out. */ |
906 | | if (mcview_display_line (view, &view->dpy_state_bottom, -1, ¶graph_ended) == 0) |
| 915 | if (mcview_display_line (view, &view->dpy_state_bottom, -1, ¶graph_ended, NULL) == 0) |
907 | 916 | break; |
908 | 917 | |
909 | 918 | /* Okay, there's enough data. Move by 1 row at the top, too. No need to check for |
… |
… |
mcview_ascii_move_down (mcview_t * view, off_t lines) |
916 | 925 | } |
917 | 926 | else |
918 | 927 | { |
919 | | mcview_display_line (view, &view->dpy_state_top, -1, ¶graph_ended); |
| 928 | mcview_display_line (view, &view->dpy_state_top, -1, ¶graph_ended, NULL); |
920 | 929 | if (!paragraph_ended) |
921 | 930 | view->dpy_paragraph_skip_lines++; |
922 | 931 | else |
… |
… |
mcview_ascii_move_up (mcview_t * view, off_t lines) |
987 | 996 | mcview_state_machine_init (&view->dpy_state_top, view->dpy_start); |
988 | 997 | view->dpy_paragraph_skip_lines -= lines; |
989 | 998 | for (i = 0; i < view->dpy_paragraph_skip_lines; i++) |
990 | | mcview_display_line (view, &view->dpy_state_top, -1, NULL); |
| 999 | mcview_display_line (view, &view->dpy_state_top, -1, NULL, NULL); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | /* --------------------------------------------------------------------------------------------- */ |
| 1004 | |
| 1005 | void |
| 1006 | mcview_ascii_moveto_bol (mcview_t * view) |
| 1007 | { |
| 1008 | if (!view->text_wrap_mode) |
| 1009 | { |
| 1010 | view->dpy_text_column = 0; |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /* --------------------------------------------------------------------------------------------- */ |
| 1015 | |
| 1016 | void |
| 1017 | mcview_ascii_moveto_eol (mcview_t * view) |
| 1018 | { |
| 1019 | if (!view->text_wrap_mode) |
| 1020 | { |
| 1021 | mcview_state_machine_t state; |
| 1022 | off_t linewidth; |
| 1023 | |
| 1024 | /* Get the width of the topmost paragraph. */ |
| 1025 | mcview_state_machine_init (&state, view->dpy_start); |
| 1026 | mcview_display_line (view, &state, -1, NULL, &linewidth); |
| 1027 | view->dpy_text_column = |
| 1028 | (linewidth > view->data_area.width) ? (linewidth - view->data_area.width) : 0; |
991 | 1029 | } |
992 | 1030 | } |
993 | 1031 | |
diff --git a/src/viewer/internal.h b/src/viewer/internal.h
index fc665db..ffadb81 100644
a
|
b
|
void mcview_display_text (mcview_t *); |
243 | 243 | void mcview_state_machine_init (mcview_state_machine_t *, off_t); |
244 | 244 | void mcview_ascii_move_down (mcview_t *, off_t); |
245 | 245 | void mcview_ascii_move_up (mcview_t *, off_t); |
| 246 | void mcview_ascii_moveto_bol (mcview_t *); |
| 247 | void mcview_ascii_moveto_eol (mcview_t *); |
246 | 248 | |
247 | 249 | /* coord_cache.c: */ |
248 | 250 | coord_cache_t *coord_cache_new (void); |
diff --git a/src/viewer/move.c b/src/viewer/move.c
index b7938ac..c956bf4 100644
a
|
b
|
mcview_moveto_bol (mcview_t * view) |
277 | 277 | if (view->hex_mode) |
278 | 278 | { |
279 | 279 | view->hex_cursor -= view->hex_cursor % view->bytes_per_line; |
| 280 | view->dpy_text_column = 0; |
280 | 281 | } |
281 | | else if (!view->text_wrap_mode) |
| 282 | else |
282 | 283 | { |
283 | | view->dpy_start = mcview_bol (view, view->dpy_start, 0); |
284 | | view->dpy_paragraph_skip_lines = 0; |
285 | | view->dpy_wrap_dirty = TRUE; |
| 284 | mcview_ascii_moveto_bol (view); |
286 | 285 | } |
287 | | view->dpy_text_column = 0; |
288 | 286 | mcview_movement_fixups (view, TRUE); |
289 | 287 | } |
290 | 288 | |
… |
… |
mcview_moveto_eol (mcview_t * view) |
311 | 309 | } |
312 | 310 | else |
313 | 311 | { |
314 | | off_t eol; |
315 | | bol = mcview_bol (view, view->dpy_start, 0); |
316 | | eol = mcview_eol (view, view->dpy_start, mcview_get_filesize (view)); |
317 | | if (!view->utf8) |
318 | | { |
319 | | if (eol > bol) |
320 | | view->dpy_text_column = eol - bol; |
321 | | } |
322 | | else |
323 | | { |
324 | | char *str = NULL; |
325 | | switch (view->datasource) |
326 | | { |
327 | | case DS_STDIO_PIPE: |
328 | | case DS_VFS_PIPE: |
329 | | str = mcview_get_ptr_growing_buffer (view, bol); |
330 | | break; |
331 | | case DS_FILE: |
332 | | str = mcview_get_ptr_file (view, bol); |
333 | | break; |
334 | | case DS_STRING: |
335 | | str = mcview_get_ptr_string (view, bol); |
336 | | break; |
337 | | case DS_NONE: |
338 | | break; |
339 | | } |
340 | | if (str != NULL && eol > bol) |
341 | | view->dpy_text_column = g_utf8_strlen (str, eol - bol); |
342 | | else |
343 | | view->dpy_text_column = eol - bol; |
344 | | } |
345 | | |
346 | | if (view->dpy_text_column < (off_t) view->data_area.width) |
347 | | view->dpy_text_column = 0; |
348 | | else |
349 | | view->dpy_text_column = view->dpy_text_column - (off_t) view->data_area.width; |
| 312 | mcview_ascii_moveto_eol (view); |
350 | 313 | } |
351 | 314 | mcview_movement_fixups (view, FALSE); |
352 | 315 | } |