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)) |
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 | } |
1153 | 1185 | } |
1154 | 1186 | |
1155 | 1187 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
|
1311 | 1343 | int side, width; |
1312 | 1344 | GString *format_txt; |
1313 | 1345 | |
1314 | | if (!panel->split) |
1315 | | adjust_top_file (panel); |
| 1346 | adjust_top_file (panel); |
1316 | 1347 | |
1317 | 1348 | widget_erase (&panel->widget); |
1318 | 1349 | show_dir (panel); |
… |
… |
|
1743 | 1774 | |
1744 | 1775 | /* --------------------------------------------------------------------------------------------- */ |
1745 | 1776 | |
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 | 1777 | static void |
1759 | 1778 | unselect_item (WPanel * panel) |
1760 | 1779 | { |
… |
… |
|
3914 | 3933 | void |
3915 | 3934 | select_item (WPanel * panel) |
3916 | 3935 | { |
3917 | | int items = ITEMS (panel); |
3918 | | |
3919 | 3936 | /* Although currently all over the code we set the selection and |
3920 | 3937 | top file to decent values before calling select_item, I could |
3921 | 3938 | forget it someday, so it's better to do the actual fitting here */ |
3922 | 3939 | |
3923 | | if (panel->top_file < 0) |
3924 | | panel->top_file = 0; |
3925 | | |
3926 | 3940 | if (panel->selected < 0) |
3927 | 3941 | panel->selected = 0; |
3928 | 3942 | |
3929 | 3943 | if (panel->selected > panel->count - 1) |
3930 | 3944 | panel->selected = panel->count - 1; |
3931 | 3945 | |
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); |
3947 | 3947 | |
3948 | 3948 | panel->dirty = 1; |
3949 | 3949 | |