Ticket #3250: 0002-3250c12.patch

File 0002-3250c12.patch, 8.9 KB (added by egmont, 4 years ago)

Fix for comment 12 (jumping to EOL in first line)

  • src/viewer/ascii.c

    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 
    551551 * @param row print to this row 
    552552 * @param paragraph_ended store TRUE if paragraph ended by newline or EOF, FALSE if wraps to next 
    553553 *   line 
     554 * @param linewidth store the width of the line here 
    554555 * @return the number of rows, that is, 0 if we were already at EOF, otherwise 1 
    555556 */ 
    556557static int 
    557558mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, 
    558                      gboolean * paragraph_ended) 
     559                     gboolean * paragraph_ended, off_t * linewidth) 
    559560{ 
    560561    const screen_dimen left = view->data_area.left; 
    561562    const screen_dimen top = view->data_area.top; 
    mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, 
    570571    if (paragraph_ended != NULL) 
    571572        *paragraph_ended = TRUE; 
    572573 
    573     if (!view->text_wrap_mode && (row < 0 || row >= (int) height)) 
     574    if (!view->text_wrap_mode && (row < 0 || row >= (int) height) && linewidth == NULL) 
    574575    { 
    575576        /* Optimization: Fast forward to the end of the line, rather than carefully 
    576577         * parsing and then not actually displaying it. */ 
    mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, 
    594595        state_saved = *state; 
    595596        n = mcview_next_combining_char_sequence (view, state, cs, 1 + MAX_COMBINING_CHARS, &color); 
    596597        if (n == 0) 
     598        { 
     599            if (linewidth != NULL) 
     600                *linewidth = col; 
    597601            return (col > 0) ? 1 : 0; 
     602        } 
    598603 
    599604        if (view->search_start <= state->offset && state->offset < view->search_end) 
    600605            color = SELECTED_COLOR; 
    mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, 
    603608        { 
    604609            /* New line: reset all formatting state for the next paragraph. */ 
    605610            mcview_state_machine_init (state, state->offset); 
     611            if (linewidth != NULL) 
     612                *linewidth = col; 
    606613            return 1; 
    607614        } 
    608615 
    mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, 
    638645            *state = state_saved; 
    639646            if (paragraph_ended != NULL) 
    640647                *paragraph_ended = FALSE; 
     648            if (linewidth != NULL) 
     649                *linewidth = col; 
    641650            return 1; 
    642651        } 
    643652 
    mcview_display_line (mcview_t * view, mcview_state_machine_t * state, int row, 
    699708        col += charwidth; 
    700709        state->unwrapped_column += charwidth; 
    701710 
    702         if (!view->text_wrap_mode && col >= dpy_text_column + width) 
     711        if (!view->text_wrap_mode && col >= dpy_text_column + width && linewidth == NULL) 
    703712        { 
    704713            /* Optimization: Fast forward to the end of the line, rather than carefully 
    705714             * parsing and then not actually displaying it. */ 
    mcview_display_paragraph (mcview_t * view, mcview_state_machine_t * state, int r 
    748757    { 
    749758        gboolean paragraph_ended; 
    750759 
    751         lines += mcview_display_line (view, state, row, &paragraph_ended); 
     760        lines += mcview_display_line (view, state, row, &paragraph_ended, NULL); 
    752761        if (paragraph_ended) 
    753762            return lines; 
    754763 
    mcview_wrap_fixup (mcview_t * view) 
    793802        gboolean paragraph_ended; 
    794803 
    795804        state_prev = view->dpy_state_top; 
    796         if (mcview_display_line (view, &view->dpy_state_top, -1, &paragraph_ended) == 0) 
     805        if (mcview_display_line (view, &view->dpy_state_top, -1, &paragraph_ended, NULL) == 0) 
    797806            break; 
    798807        if (paragraph_ended) 
    799808        { 
    mcview_ascii_move_down (mcview_t * view, off_t lines) 
    903912        /* See if there's still data below the bottom line, by imaginarily displaying one 
    904913         * more line. This takes care of reading more data into growbuf, if required. 
    905914         * 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, &paragraph_ended) == 0) 
     915        if (mcview_display_line (view, &view->dpy_state_bottom, -1, &paragraph_ended, NULL) == 0) 
    907916            break; 
    908917 
    909918        /* 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) 
    916925        } 
    917926        else 
    918927        { 
    919             mcview_display_line (view, &view->dpy_state_top, -1, &paragraph_ended); 
     928            mcview_display_line (view, &view->dpy_state_top, -1, &paragraph_ended, NULL); 
    920929            if (!paragraph_ended) 
    921930                view->dpy_paragraph_skip_lines++; 
    922931            else 
    mcview_ascii_move_up (mcview_t * view, off_t lines) 
    987996        mcview_state_machine_init (&view->dpy_state_top, view->dpy_start); 
    988997        view->dpy_paragraph_skip_lines -= lines; 
    989998        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 
     1005void 
     1006mcview_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 
     1016void 
     1017mcview_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; 
    9911029    } 
    9921030} 
    9931031 
  • src/viewer/internal.h

    diff --git a/src/viewer/internal.h b/src/viewer/internal.h
    index fc665db..ffadb81 100644
    a b void mcview_display_text (mcview_t *); 
    243243void mcview_state_machine_init (mcview_state_machine_t *, off_t); 
    244244void mcview_ascii_move_down (mcview_t *, off_t); 
    245245void mcview_ascii_move_up (mcview_t *, off_t); 
     246void mcview_ascii_moveto_bol (mcview_t *); 
     247void mcview_ascii_moveto_eol (mcview_t *); 
    246248 
    247249/* coord_cache.c: */ 
    248250coord_cache_t *coord_cache_new (void); 
  • src/viewer/move.c

    diff --git a/src/viewer/move.c b/src/viewer/move.c
    index b7938ac..c956bf4 100644
    a b mcview_moveto_bol (mcview_t * view) 
    277277    if (view->hex_mode) 
    278278    { 
    279279        view->hex_cursor -= view->hex_cursor % view->bytes_per_line; 
     280        view->dpy_text_column = 0; 
    280281    } 
    281     else if (!view->text_wrap_mode) 
     282    else 
    282283    { 
    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); 
    286285    } 
    287     view->dpy_text_column = 0; 
    288286    mcview_movement_fixups (view, TRUE); 
    289287} 
    290288 
    mcview_moveto_eol (mcview_t * view) 
    311309    } 
    312310    else 
    313311    { 
    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); 
    350313    } 
    351314    mcview_movement_fixups (view, FALSE); 
    352315}