diff -ur mc-4.8.1.orig/src/filemanager/panel.c mc-4.8.1/src/filemanager/panel.c
old
|
new
|
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | /* --------------------------------------------------------------------------------------------- */ |
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 */ |
| 1144 | static int |
| 1145 | ITEMS (WPanel * p) |
| 1146 | { |
| 1147 | if (p->split) |
| 1148 | return llines (p) * 2; |
| 1149 | else |
| 1150 | return llines (p); |
| 1151 | } |
| 1152 | |
| 1153 | /* --------------------------------------------------------------------------------------------- */ |
1143 | 1154 | |
1144 | 1155 | static void |
1145 | 1156 | adjust_top_file (WPanel * panel) |
1146 | 1157 | { |
1147 | | int old_top = panel->top_file; |
| 1158 | int items = ITEMS (panel); |
1148 | 1159 | |
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) |
1150 | 1169 | 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; |
1153 | 1179 | } |
1154 | 1180 | |
1155 | 1181 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
|
1311 | 1337 | int side, width; |
1312 | 1338 | GString *format_txt; |
1313 | 1339 | |
1314 | | if (!panel->split) |
1315 | | adjust_top_file (panel); |
| 1340 | adjust_top_file (panel); |
1316 | 1341 | |
1317 | 1342 | widget_erase (&panel->widget); |
1318 | 1343 | show_dir (panel); |
… |
… |
|
1743 | 1768 | |
1744 | 1769 | /* --------------------------------------------------------------------------------------------- */ |
1745 | 1770 | |
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 | | |
1758 | 1771 | static void |
1759 | 1772 | unselect_item (WPanel * panel) |
1760 | 1773 | { |
… |
… |
|
3914 | 3927 | void |
3915 | 3928 | select_item (WPanel * panel) |
3916 | 3929 | { |
3917 | | int items = ITEMS (panel); |
3918 | | |
3919 | 3930 | /* Although currently all over the code we set the selection and |
3920 | 3931 | top file to decent values before calling select_item, I could |
3921 | 3932 | forget it someday, so it's better to do the actual fitting here */ |
3922 | 3933 | |
3923 | | if (panel->top_file < 0) |
3924 | | panel->top_file = 0; |
3925 | | |
3926 | 3934 | if (panel->selected < 0) |
3927 | 3935 | panel->selected = 0; |
3928 | 3936 | |
3929 | 3937 | if (panel->selected > panel->count - 1) |
3930 | 3938 | panel->selected = panel->count - 1; |
3931 | 3939 | |
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); |
3947 | 3941 | |
3948 | 3942 | panel->dirty = 1; |
3949 | 3943 | |