Ticket #2371: mc-movement_position_v2.patch

File mc-movement_position_v2.patch, 12.8 KB (added by gotar, 13 years ago)
  • src/viewer/coord_cache.c

    diff -urp mc-4.7.5.4/src/viewer/coord_cache.c mc-4.7.5.4.new/src/viewer/coord_cache.c
    old new mcview_ccache_lookup (mcview_t * view, c 
    435435 
    436436    tty_disable_interrupt_key (); 
    437437 
     438    coord->cc_line = current.cc_line; 
    438439    if (lookup_what == CCACHE_OFFSET) 
    439440    { 
    440441        coord->cc_offset = current.cc_offset; 
    441442    } 
    442443    else 
    443444    { 
    444         coord->cc_line = current.cc_line; 
    445445        coord->cc_column = current.cc_column; 
    446446        coord->cc_nroff_column = current.cc_nroff_column; 
    447447    } 
  • src/viewer/dialogs.c

    diff -urp mc-4.7.5.4/src/viewer/dialogs.c mc-4.7.5.4.new/src/viewer/dialogs.c
    old new mcview_dialog_goto (mcview_t * view, off 
    274274                *offset = addr * mcview_get_filesize (view) / 100; 
    275275                if (!view->hex_mode) 
    276276                    *offset = mcview_bol (view, *offset, 0); 
     277                view->dpy_lines_status = LINE_COUNT_UNKNOWN; 
     278                view->dpy_start_line = 0; 
    277279                break; 
    278280            case MC_VIEW_GOTO_OFFSET_DEC: 
    279281            case MC_VIEW_GOTO_OFFSET_HEX: 
     282                view->dpy_lines_status = LINE_COUNT_UNKNOWN; 
     283                view->dpy_start_line = 0; 
    280284                *offset = addr; 
    281285                if (!view->hex_mode) 
    282286                    *offset = mcview_bol (view, *offset, 0); 
  • src/viewer/display.c

    diff -urp mc-4.7.5.4/src/viewer/display.c mc-4.7.5.4.new/src/viewer/display.c
    old new mcview_display_status (mcview_t * view) 
    135135    const screen_dimen height = view->status_area.height; 
    136136    const char *file_label; 
    137137    screen_dimen file_label_width; 
     138    screen_dimen extra_space = 0; 
    138139 
    139140    if (height < 1) 
    140141        return; 
    mcview_display_status (mcview_t * view) 
    148149    if (width > 40) 
    149150    { 
    150151        char buffer[BUF_TINY]; 
    151         widget_move (view, top, width - 32); 
    152152        if (view->hex_mode) 
     153        { 
     154            widget_move (view, top, width - 32); 
    153155            tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor); 
     156        } 
    154157        else 
    155158        { 
    156159            size_trunc_len (buffer, 5, mcview_get_filesize (view), 0, panels_options.kilobyte_si); 
     160            if (width - file_label_width - 32 > 6) 
     161            { 
     162                extra_space = width-file_label_width-32-4; 
     163                widget_move (view, top, width - 32 - extra_space); 
     164                tty_printf ("C:%ld L:", (ulong) view->dpy_text_column); 
     165                if (view->dpy_lines_status == LINE_COUNT_UNKNOWN) 
     166                    tty_print_string("~? "); 
     167                else if (view->dpy_lines_status == LINE_COUNT_BACKWARD) 
     168                    tty_print_string("EOF"); 
     169                tty_printf ("%ld+%ld=%ld /%ld", (long) view->dpy_start_line, (ulong) view->dpy_visible_lines, (long) (view->dpy_start_line+view->dpy_visible_lines), view->dpy_lines_total); 
     170                if (view->dpy_lines_status != LINE_COUNT_SET) 
     171                    tty_print_string("+"); 
     172            } 
     173            widget_move (view, top, width - 32); 
    157174            tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end, 
    158175                        buffer, mcview_may_still_grow (view) ? "+" : " ", 
    159176#ifdef HAVE_CHARSET 
    mcview_display_status (mcview_t * view) 
    166183    } 
    167184    widget_move (view, top, left); 
    168185    if (width > 40) 
    169         tty_print_string (str_fit_to_term (file_label, width - 34, J_LEFT_FIT)); 
     186        tty_print_string (str_fit_to_term (file_label, width - 34 - extra_space, J_LEFT_FIT)); 
    170187    else 
    171188        tty_print_string (str_fit_to_term (file_label, width - 5, J_LEFT_FIT)); 
    172189    if (width > 26) 
  • src/viewer/internal.h

    diff -urp mc-4.7.5.4/src/viewer/internal.h mc-4.7.5.4.new/src/viewer/internal.h
    old new typedef struct mcview_struct 
    138138    screen_dimen dpy_frame_size;        /* Size of the frame surrounding the real viewer */ 
    139139    off_t dpy_start;            /* Offset of the displayed data */ 
    140140    off_t dpy_end;              /* Offset after the displayed data */ 
     141    off_t dpy_start_line;       /* Line number of beginning of the displayed data */ 
     142    off_t dpy_visible_lines;    /* Number of lines of the displayed data */ 
     143    off_t dpy_lines_total;      /* Number of lines of entire file */ 
     144    enum 
     145    { 
     146        LINE_COUNT_UNKNOWN = -2, 
     147        LINE_COUNT_BACKWARD = -1, 
     148        LINE_COUNT_GROWING = 0, 
     149        LINE_COUNT_SET = 1 
     150    } dpy_lines_status;         /* Line counter status */ 
    141151    off_t dpy_text_column;      /* Number of skipped columns in non-wrap 
    142152                                 * text mode */ 
    143153    off_t hex_cursor;           /* Hexview cursor position in file */ 
  • src/viewer/lib.c

    diff -urp mc-4.7.5.4/src/viewer/lib.c mc-4.7.5.4.new/src/viewer/lib.c
    old new mcview_init (mcview_t * view) 
    202202    view->dpy_start = 0; 
    203203    view->dpy_text_column = 0; 
    204204    view->dpy_end = 0; 
     205    view->dpy_start_line = 0; 
     206    view->dpy_visible_lines = 0; 
     207    view->dpy_lines_total = 0; 
     208    view->dpy_lines_status = LINE_COUNT_GROWING; 
    205209    view->hex_cursor = 0; 
    206210    view->cursor_col = 0; 
    207211    view->cursor_row = 0; 
  • src/viewer/mcviewer.c

    diff -urp mc-4.7.5.4/src/viewer/mcviewer.c mc-4.7.5.4.new/src/viewer/mcviewer.c
    old new mcview_load (mcview_t * view, const char 
    390390  finish: 
    391391    view->command = g_strdup (command); 
    392392    view->dpy_start = 0; 
     393    view->dpy_start_line = 0; 
     394    view->dpy_visible_lines = 0; 
     395    view->dpy_lines_total = 0; 
     396    view->dpy_lines_status = LINE_COUNT_GROWING; 
    393397    view->search_start = 0; 
    394398    view->search_end = 0; 
    395399    view->dpy_text_column = 0; 
    mcview_load (mcview_t * view, const char 
    407411        load_file_position (canon_fname, &line, &col, &new_offset, &view->saved_bookmarks); 
    408412        new_offset = min (new_offset, mcview_get_filesize (view)); 
    409413        view->dpy_start = mcview_bol (view, new_offset, 0); 
     414        view->dpy_lines_status = LINE_COUNT_UNKNOWN; 
    410415        g_free (canon_fname); 
    411416    } 
    412417    else if (start_line > 0) 
  • src/viewer/move.c

    diff -urp mc-4.7.5.4/src/viewer/move.c mc-4.7.5.4.new/src/viewer/move.c
    old new mcview_move_up (mcview_t * view, off_t l 
    128128                         * and move down all but the last rows */ 
    129129                        new_offset = view->dpy_start - (off_t) last_row_length; 
    130130                    } 
     131                    view->dpy_start_line--; 
    131132                } 
    132133                else 
    133134                { 
    mcview_move_up (mcview_t * view, off_t l 
    143144                /* if unwrapped -> current BOL equals dpy_start, just find BOL of previous line */ 
    144145                new_offset = view->dpy_start - 1; 
    145146                view->dpy_start = mcview_bol (view, new_offset, 0); 
     147                view->dpy_start_line--; 
    146148            } 
    147149        } 
    148150    } 
    mcview_move_down (mcview_t * view, off_t 
    193195                else 
    194196                    new_offset = mcview_eol (view, view->dpy_start, last_byte); 
    195197                if (new_offset < last_byte) 
     198                { 
    196199                    view->dpy_start = new_offset; 
     200                    if(new_offset == mcview_bol (view, new_offset, new_offset - (off_t) 1)) 
     201                        view->dpy_start_line++; 
     202                } 
    197203                if (view->dpy_end >= last_byte) 
    198204                    break; 
    199205            } 
    mcview_move_down (mcview_t * view, off_t 
    210216                else 
    211217                    new_offset = mcview_eol (view, view->dpy_start, last_byte); 
    212218                if (new_offset < last_byte) 
     219                { 
    213220                    view->dpy_start = new_offset; 
     221                    if(new_offset == mcview_bol (view, new_offset, new_offset - (off_t) 1)) 
     222                        view->dpy_start_line++; 
     223                } 
    214224            } 
    215225        } 
    216226    } 
    void 
    298308mcview_moveto_top (mcview_t * view) 
    299309{ 
    300310    view->dpy_start = 0; 
     311    view->dpy_start_line = 0; 
    301312    view->hex_cursor = 0; 
    302313    view->dpy_text_column = 0; 
    303314    mcview_movement_fixups (view, TRUE); 
     315    if (view->dpy_lines_status != LINE_COUNT_SET) 
     316        view->dpy_lines_status = LINE_COUNT_GROWING; 
    304317} 
    305318 
    306319/* --------------------------------------------------------------------------------------------- */ 
    mcview_moveto_bottom (mcview_t * view) 
    327340        const off_t datalines = view->data_area.height; 
    328341 
    329342        view->dpy_start = filesize; 
     343        if (view->dpy_lines_status != LINE_COUNT_SET) { 
     344            view->dpy_lines_status = LINE_COUNT_BACKWARD; 
     345            view->dpy_start_line = 0; 
     346        } 
     347        else 
     348            view->dpy_start_line=view->dpy_lines_total; 
    330349        mcview_move_up (view, datalines); 
    331350    } 
    332351} 
    mcview_coord_to_offset (mcview_t * view, 
    447466    coord.cc_nroff_column = column; 
    448467    mcview_ccache_lookup (view, &coord, CCACHE_OFFSET); 
    449468    *ret_offset = coord.cc_offset; 
     469    view->dpy_start_line = coord.cc_line; 
    450470} 
    451471 
    452472/* --------------------------------------------------------------------------------------------- */ 
  • src/viewer/plain.c

    diff -urp mc-4.7.5.4/src/viewer/plain.c mc-4.7.5.4.new/src/viewer/plain.c
    old new mcview_display_text (mcview_t * view) 
    8484 
    8585    /* Find the first displayable changed byte */ 
    8686    from = view->dpy_start; 
     87    view->dpy_visible_lines = 0; 
    8788    while ((curr != NULL) && (curr->offset < from)) 
    8889        curr = curr->next; 
    8990 
    mcview_display_text (mcview_t * view) 
    101102 
    102103            c = mcview_get_utf (view, from, &cw, &read_res); 
    103104            if (!read_res) 
     105            { 
     106                if (view->dpy_lines_status == LINE_COUNT_GROWING) 
     107                    view->dpy_lines_status = LINE_COUNT_SET; 
     108                if (view->dpy_lines_status == LINE_COUNT_UNKNOWN) { 
     109                    view->dpy_lines_status = LINE_COUNT_BACKWARD; 
     110                    view->dpy_start_line = -view->dpy_visible_lines; 
     111                } 
    104112                break; 
     113            } 
    105114        } 
    106115        else 
    107116#endif 
    108117        if (!mcview_get_byte (view, from, &c)) 
     118            { 
     119            if (view->dpy_lines_status == LINE_COUNT_GROWING) 
     120                view->dpy_lines_status = LINE_COUNT_SET; 
     121            if (view->dpy_lines_status == LINE_COUNT_UNKNOWN) { 
     122                view->dpy_lines_status = LINE_COUNT_BACKWARD; 
     123                view->dpy_start_line = -view->dpy_visible_lines; 
     124            } 
    109125            break; 
     126        } 
    110127 
    111128        last_row = FALSE; 
    112129        from++; 
    mcview_display_text (mcview_t * view) 
    130147        { 
    131148            col = 0; 
    132149            row++; 
     150            view->dpy_visible_lines++; 
    133151            continue; 
    134152        } 
    135153 
    mcview_display_text (mcview_t * view) 
    193211#endif 
    194212    } 
    195213 
     214    if (view->dpy_lines_status != LINE_COUNT_BACKWARD && view->dpy_start_line+view->dpy_visible_lines>view->dpy_lines_total) 
     215        view->dpy_lines_total = view->dpy_start_line+view->dpy_visible_lines; 
     216    else if (view->dpy_lines_status != LINE_COUNT_BACKWARD && view->dpy_lines_total<-view->dpy_start_line+view->dpy_visible_lines) 
     217        view->dpy_lines_total = -view->dpy_start_line+view->dpy_visible_lines; 
     218    else if (view->dpy_lines_total<-view->dpy_start_line) 
     219        view->dpy_lines_total = -view->dpy_start_line; 
     220    if (view->dpy_start == 0) 
     221    { 
     222        view->dpy_start_line = 0; 
     223        if (view->dpy_lines_status == LINE_COUNT_BACKWARD) 
     224            view->dpy_lines_status = LINE_COUNT_SET; 
     225        if (view->dpy_lines_status == LINE_COUNT_UNKNOWN) 
     226            view->dpy_lines_status = LINE_COUNT_GROWING; 
     227    } 
    196228    view->dpy_end = from; 
    197229    if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0') 
    198230    { 
  • src/viewer/search.c

    diff -urp mc-4.7.5.4/src/viewer/search.c mc-4.7.5.4.new/src/viewer/search.c
    old new mcview_do_search (mcview_t * view) 
    325325    } 
    326326    while (mcview_may_still_grow (view)); 
    327327 
     328    view->dpy_lines_status = LINE_COUNT_UNKNOWN; 
     329    view->dpy_start_line = 0; 
     330 
    328331    if (view->search_start != 0 && !isFound && need_search_again 
    329332        && !mcview_search_options.backwards) 
    330333    {