Ticket #2684: mc-4.8.1-cursor-after-resize-try3.patch

File mc-4.8.1-cursor-after-resize-try3.patch, 3.6 KB (added by egmont, 12 years ago)

Alternate version, equally good as try2

  • src/filemanager/panel.c

    diff -ur mc-4.8.1.orig/src/filemanager/panel.c mc-4.8.1/src/filemanager/panel.c
    old new  
    11391139} 
    11401140 
    11411141/* --------------------------------------------------------------------------------------------- */ 
    1142 /** To be used only by long_frame and full_frame to adjust top_file */ 
     1142 
     1143/* Returns the number of items in the given panel */ 
     1144static int 
     1145ITEMS (WPanel * p) 
     1146{ 
     1147    if (p->split) 
     1148        return llines (p) * 2; 
     1149    else 
     1150        return llines (p); 
     1151} 
     1152 
     1153/* --------------------------------------------------------------------------------------------- */ 
    11431154 
    11441155static void 
    11451156adjust_top_file (WPanel * panel) 
    11461157{ 
    1147     int old_top = panel->top_file; 
     1158    int items = ITEMS (panel); 
    11481159 
    1149     if (panel->selected - old_top > llines (panel)) 
     1160    /* If there's not enough room to display all files (count > items) then: 
     1161       - top_file has to be in the range [selected-items+1, selected] so that 
     1162         the selected file is visible, 
     1163       - top_file should be in the range [0, count-items] so that there's 
     1164         no empty space wasted, 
     1165       - within these ranges, adjust it by as little as possible. 
     1166       If all files fit (count <= items) then top_file should be set to 0 
     1167       to show them all, this is done by the last two checks. */ 
     1168    if (panel->top_file > panel->selected) 
    11501169        panel->top_file = panel->selected; 
    1151     if (old_top - panel->count > llines (panel)) 
    1152         panel->top_file = panel->count - llines (panel); 
     1170 
     1171    if (panel->top_file < panel->selected - items + 1) 
     1172        panel->top_file = panel->selected - items + 1; 
     1173 
     1174    if (panel->top_file > panel->count - items) 
     1175        panel->top_file = panel->count - items; 
     1176 
     1177    if (panel->top_file < 0) 
     1178        panel->top_file = 0; 
    11531179} 
    11541180 
    11551181/* --------------------------------------------------------------------------------------------- */ 
     
    13111337    int side, width; 
    13121338    GString *format_txt; 
    13131339 
    1314     if (!panel->split) 
    1315         adjust_top_file (panel); 
     1340    adjust_top_file (panel); 
    13161341 
    13171342    widget_erase (&panel->widget); 
    13181343    show_dir (panel); 
     
    17431768 
    17441769/* --------------------------------------------------------------------------------------------- */ 
    17451770 
    1746 /* Returns the number of items in the given panel */ 
    1747 static int 
    1748 ITEMS (WPanel * p) 
    1749 { 
    1750     if (p->split) 
    1751         return llines (p) * 2; 
    1752     else 
    1753         return llines (p); 
    1754 } 
    1755  
    1756 /* --------------------------------------------------------------------------------------------- */ 
    1757  
    17581771static void 
    17591772unselect_item (WPanel * panel) 
    17601773{ 
     
    39143927void 
    39153928select_item (WPanel * panel) 
    39163929{ 
    3917     int items = ITEMS (panel); 
    3918  
    39193930    /* Although currently all over the code we set the selection and 
    39203931       top file to decent values before calling select_item, I could 
    39213932       forget it someday, so it's better to do the actual fitting here */ 
    39223933 
    3923     if (panel->top_file < 0) 
    3924         panel->top_file = 0; 
    3925  
    39263934    if (panel->selected < 0) 
    39273935        panel->selected = 0; 
    39283936 
    39293937    if (panel->selected > panel->count - 1) 
    39303938        panel->selected = panel->count - 1; 
    39313939 
    3932     if (panel->top_file > panel->count - 1) 
    3933         panel->top_file = panel->count - 1; 
    3934  
    3935     if ((panel->count - panel->top_file) < items) 
    3936     { 
    3937         panel->top_file = panel->count - items; 
    3938         if (panel->top_file < 0) 
    3939             panel->top_file = 0; 
    3940     } 
    3941  
    3942     if (panel->selected < panel->top_file) 
    3943         panel->top_file = panel->selected; 
    3944  
    3945     if ((panel->selected - panel->top_file) >= items) 
    3946         panel->top_file = panel->selected - items + 1; 
     3940    adjust_top_file (panel); 
    39473941 
    39483942    panel->dirty = 1; 
    39493943