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

File mc-4.8.1-cursor-after-resize-try2.patch, 3.7 KB (added by egmont, 13 years ago)

A much better version

  • 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)) 
    1150         panel->top_file = panel->selected; 
    1151     if (old_top - panel->count > llines (panel)) 
    1152         panel->top_file = panel->count - llines (panel); 
     1160    if (panel->count <= items) 
     1161    { 
     1162        /* If all files fit, show them all. */ 
     1163        panel->top_file = 0; 
     1164    } 
     1165    else 
     1166    { 
     1167        /* top_file has to be in the range [selected-items+1, selected] so that 
     1168           the selected file is visible. 
     1169           top_file should be in the range [0, count-items] so that there's 
     1170           no empty space wasted. 
     1171           Within these ranges, adjust it by as little as possible. */ 
     1172 
     1173        if (panel->top_file < 0) 
     1174            panel->top_file = 0; 
     1175 
     1176        if (panel->top_file < panel->selected - items + 1) 
     1177            panel->top_file = panel->selected - items + 1; 
     1178 
     1179        if (panel->top_file > panel->count - items) 
     1180            panel->top_file = panel->count - items; 
     1181 
     1182        if (panel->top_file > panel->selected) 
     1183            panel->top_file = panel->selected; 
     1184    } 
    11531185} 
    11541186 
    11551187/* --------------------------------------------------------------------------------------------- */ 
     
    13111343    int side, width; 
    13121344    GString *format_txt; 
    13131345 
    1314     if (!panel->split) 
    1315         adjust_top_file (panel); 
     1346    adjust_top_file (panel); 
    13161347 
    13171348    widget_erase (&panel->widget); 
    13181349    show_dir (panel); 
     
    17431774 
    17441775/* --------------------------------------------------------------------------------------------- */ 
    17451776 
    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  
    17581777static void 
    17591778unselect_item (WPanel * panel) 
    17601779{ 
     
    39143933void 
    39153934select_item (WPanel * panel) 
    39163935{ 
    3917     int items = ITEMS (panel); 
    3918  
    39193936    /* Although currently all over the code we set the selection and 
    39203937       top file to decent values before calling select_item, I could 
    39213938       forget it someday, so it's better to do the actual fitting here */ 
    39223939 
    3923     if (panel->top_file < 0) 
    3924         panel->top_file = 0; 
    3925  
    39263940    if (panel->selected < 0) 
    39273941        panel->selected = 0; 
    39283942 
    39293943    if (panel->selected > panel->count - 1) 
    39303944        panel->selected = panel->count - 1; 
    39313945 
    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; 
     3946    adjust_top_file (panel); 
    39473947 
    39483948    panel->dirty = 1; 
    39493949