32
32
33
33
#include <config.h>
34
34
35
+ #include <limits.h> // UINT_MAX
35
36
#include <stdio.h>
36
37
#include <stdlib.h>
37
38
#include <string.h>
@@ -721,27 +722,25 @@ format_file (WPanel *panel, int file_index, int width, file_attr_t attr, gboolea
721
722
if (len <= 0 )
722
723
break ;
723
724
724
- if (!isstatus && panel -> content_shift > -1 && strcmp (fi -> id , "name" ) == 0 )
725
+ if (!isstatus && strcmp (fi -> id , "name" ) == 0 )
725
726
{
726
- int str_len ;
727
- int i ;
727
+ const int str_len = str_length ( txt ) ;
728
+ const unsigned int len_diff = ( unsigned int ) DOZ ( str_len , len ) ;
728
729
729
730
* field_length = len + 1 ;
730
731
731
- str_len = str_length (txt );
732
- i = MAX (0 , str_len - len );
733
- panel -> max_shift = MAX (panel -> max_shift , i );
734
- i = MIN (panel -> content_shift , i );
732
+ panel -> max_shift = MAX (panel -> max_shift , len_diff );
735
733
736
- if (i > -1 )
734
+ if (len_diff != 0 )
737
735
{
738
- name_offset = str_offset_to_pos (txt , i );
739
- if (str_len > len )
740
- {
741
- res = FILENAME_SCROLL_LEFT ;
742
- if (str_length (txt + name_offset ) > len )
743
- res |= FILENAME_SCROLL_RIGHT ;
744
- }
736
+ const unsigned int shift = MIN (panel -> content_shift , len_diff );
737
+
738
+ if (shift != 0 )
739
+ res |= FILENAME_SCROLL_LEFT ;
740
+
741
+ name_offset = str_offset_to_pos (txt , shift );
742
+ if (str_length (txt + name_offset ) > len )
743
+ res |= FILENAME_SCROLL_RIGHT ;
745
744
}
746
745
}
747
746
@@ -758,7 +757,7 @@ format_file (WPanel *panel, int file_index, int width, file_attr_t attr, gboolea
758
757
else
759
758
tty_lowlevel_setcolor (- color );
760
759
761
- if (!isstatus && panel -> content_shift > -1 )
760
+ if (!isstatus )
762
761
prepared_text = str_fit_to_term (txt + name_offset , len , HIDE_FIT (fi -> just_mode ));
763
762
else
764
763
prepared_text = str_fit_to_term (txt , len , fi -> just_mode );
@@ -854,18 +853,32 @@ repaint_file (WPanel *panel, int file_index, file_attr_t attr)
854
853
}
855
854
}
856
855
857
- widget_gotoyx (w , ypos , offset );
858
- tty_setcolor (NORMAL_COLOR );
859
- tty_print_string (panel_filename_scroll_left_char );
856
+ const int file_color =
857
+ attr == FATTR_CURRENT || attr == FATTR_MARKED_CURRENT ? SELECTED_COLOR : NORMAL_COLOR ;
858
+
859
+ if ((ret_frm & FILENAME_SCROLL_LEFT ) != 0 )
860
+ {
861
+ const int scroll_left_char_color =
862
+ panel -> list_format == list_long ? file_color : NORMAL_COLOR ;
863
+
864
+ widget_gotoyx (w , ypos , offset );
865
+ tty_setcolor (scroll_left_char_color );
866
+ tty_print_string (panel_filename_scroll_left_char );
867
+ }
860
868
861
869
if ((ret_frm & FILENAME_SCROLL_RIGHT ) != 0 )
862
870
{
863
871
offset += width ;
864
872
if (nth_column + 1 >= panel -> list_cols )
865
873
offset ++ ;
866
874
875
+ const int scroll_right_char_color =
876
+ panel -> list_format != list_long && g_slist_length (panel -> format ) > 2
877
+ ? file_color
878
+ : NORMAL_COLOR ;
879
+
867
880
widget_gotoyx (w , ypos , offset );
868
- tty_setcolor (NORMAL_COLOR );
881
+ tty_setcolor (scroll_right_char_color );
869
882
tty_print_string (panel_filename_scroll_right_char );
870
883
}
871
884
}
@@ -958,7 +971,7 @@ paint_dir (WPanel *panel)
958
971
959
972
items = panel_items (panel );
960
973
// reset max len of filename because we have the new max length for the new file list
961
- panel -> max_shift = -1 ;
974
+ panel -> max_shift = 0 ;
962
975
963
976
for (i = 0 ; i < items ; i ++ )
964
977
{
@@ -3194,19 +3207,16 @@ panel_select_sort_order (WPanel *panel)
3194
3207
}
3195
3208
3196
3209
/* --------------------------------------------------------------------------------------------- */
3197
-
3198
3210
/**
3199
- * panel_content_scroll_left:
3200
- * @param panel the pointer to the panel on which we operate
3201
- *
3202
- * scroll long filename to the left (decrement scroll pointer)
3211
+ * Scroll long filename to left
3203
3212
*
3213
+ * @param panel object
3204
3214
*/
3205
3215
3206
3216
static void
3207
3217
panel_content_scroll_left (WPanel * panel )
3208
3218
{
3209
- if (panel -> content_shift > -1 )
3219
+ if (panel -> content_shift != 0 )
3210
3220
{
3211
3221
if (panel -> content_shift > panel -> max_shift )
3212
3222
panel -> content_shift = panel -> max_shift ;
@@ -3219,24 +3229,58 @@ panel_content_scroll_left (WPanel *panel)
3219
3229
3220
3230
/* --------------------------------------------------------------------------------------------- */
3221
3231
/**
3222
- * panel_content_scroll_right:
3223
- * @param panel the pointer to the panel on which we operate
3224
- *
3225
- * scroll long filename to the right (increment scroll pointer)
3232
+ * Scroll long filename to right
3226
3233
*
3234
+ * @param panel object
3227
3235
*/
3228
3236
3229
3237
static void
3230
3238
panel_content_scroll_right (WPanel * panel )
3231
3239
{
3232
- if (panel -> content_shift < 0 || panel -> content_shift < panel -> max_shift )
3240
+ if (panel -> content_shift == 0 || panel -> content_shift < panel -> max_shift )
3233
3241
{
3234
3242
panel -> content_shift ++ ;
3235
3243
show_dir (panel );
3236
3244
paint_dir (panel );
3237
3245
}
3238
3246
}
3239
3247
3248
+ /* --------------------------------------------------------------------------------------------- */
3249
+ /**
3250
+ * Scroll long filename to home
3251
+ *
3252
+ * @param panel the pointer to the panel on which we operate
3253
+ */
3254
+
3255
+ static void
3256
+ panel_content_scroll_home (WPanel * panel )
3257
+ {
3258
+ panel -> content_shift = 0 ;
3259
+ show_dir (panel );
3260
+ paint_dir (panel );
3261
+ }
3262
+
3263
+ /* --------------------------------------------------------------------------------------------- */
3264
+ /**
3265
+ * Scroll long filename to end
3266
+ *
3267
+ * @param panel the pointer to the panel on which we operate
3268
+ */
3269
+
3270
+ static void
3271
+ panel_content_scroll_end (WPanel * panel )
3272
+ {
3273
+ // set content_shift to the maximum possible value
3274
+ panel -> content_shift = UINT_MAX ;
3275
+
3276
+ show_dir (panel );
3277
+ paint_dir (panel );
3278
+
3279
+ // correct content shift after UINT_MAX
3280
+ if (panel -> content_shift > panel -> max_shift )
3281
+ panel -> content_shift = panel -> max_shift ;
3282
+ }
3283
+
3240
3284
/* --------------------------------------------------------------------------------------------- */
3241
3285
3242
3286
static void
@@ -3621,6 +3665,12 @@ panel_execute_cmd (WPanel *panel, long command)
3621
3665
case CK_ScrollRight :
3622
3666
panel_content_scroll_right (panel );
3623
3667
break ;
3668
+ case CK_ScrollHome :
3669
+ panel_content_scroll_home (panel );
3670
+ break ;
3671
+ case CK_ScrollEnd :
3672
+ panel_content_scroll_end (panel );
3673
+ break ;
3624
3674
case CK_Search :
3625
3675
start_search (panel );
3626
3676
break ;
@@ -4380,8 +4430,8 @@ panel_clean_dir (WPanel *panel)
4380
4430
panel -> quick_search .active = FALSE;
4381
4431
panel -> is_panelized = FALSE;
4382
4432
panel -> dirty = TRUE;
4383
- panel -> content_shift = -1 ;
4384
- panel -> max_shift = -1 ;
4433
+ panel -> content_shift = 0 ;
4434
+ panel -> max_shift = 0 ;
4385
4435
4386
4436
dir_list_free_list (& panel -> dir );
4387
4437
}
@@ -4454,8 +4504,8 @@ panel_sized_empty_new (const char *panel_name, const WRect *r)
4454
4504
panel -> list_cols = 1 ;
4455
4505
panel -> brief_cols = 2 ;
4456
4506
panel -> dirty = TRUE;
4457
- panel -> content_shift = -1 ;
4458
- panel -> max_shift = -1 ;
4507
+ panel -> content_shift = 0 ;
4508
+ panel -> max_shift = 0 ;
4459
4509
4460
4510
panel -> list_format = list_full ;
4461
4511
panel -> user_format = g_strdup (DEFAULT_USER_FORMAT );
0 commit comments