Skip to content

Commit 9e62e51

Browse files
authored
Merge pull request #4685 from MidnightCommander/feature/fix-filename-scrolling-color
Enable filename scrolling by default and fix background color
2 parents 157f51f + 29be52e commit 9e62e51

File tree

9 files changed

+110
-44
lines changed

9 files changed

+110
-44
lines changed

doc/man/mc.1.in

+3
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ move the selection bar one page down.
519519
.B prev\-page, Alt\-v
520520
move the selection bar one page up.
521521
.TP
522+
.B Alt\-(, Alt\-)
523+
scroll long filenames to the right or left.
524+
.TP
522525
.B Alt\-o
523526
If the currently selected file is a directory, load that directory on
524527
the other panel and moves the selection to the next file. If the

doc/man/ru/mc.1.in

+3
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ Midnight Commander\-а. Для возврата к вашему приложен
567567
.B PageUp, Alt\-v
568568
Перемещает подсветку на одну страницу вверх.
569569
.TP
570+
.B Alt\-(, Alt\-)
571+
Прокручивает длинные имена файлов направо или налево.
572+
.TP
570573
.B Alt\-o
571574
Если выделенным элементом активной панели является каталог, установить
572575
этот каталог текущим в неактивной панели и перейти к следующему файлу.

lib/keybind.c

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ static name_keymap_t command_names[] = {
225225
ADD_KEYMAP_NAME (SelectExt),
226226
ADD_KEYMAP_NAME (ScrollLeft),
227227
ADD_KEYMAP_NAME (ScrollRight),
228+
ADD_KEYMAP_NAME (ScrollHome),
229+
ADD_KEYMAP_NAME (ScrollEnd),
228230
ADD_KEYMAP_NAME (PanelOtherCd),
229231
ADD_KEYMAP_NAME (PanelOtherCdLink),
230232
ADD_KEYMAP_NAME (CopySingle),

lib/keybind.h

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ enum
209209
CK_SortByMTime,
210210
CK_ScrollLeft,
211211
CK_ScrollRight,
212+
CK_ScrollHome,
213+
CK_ScrollEnd,
212214
CK_CycleListingFormat,
213215

214216
// dialog

misc/mc.default.keymap

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ Bottom = alt-gt; end; c1
129129
# SortBySize =
130130
# SortByMTime =
131131
# Filter =
132-
# ScrollLeft =
133-
# ScrollRight =
132+
ScrollLeft = alt-lparenthesis
133+
ScrollRight = alt-rparenthesis
134+
# ScrollHome =
135+
# ScrollEnd =
134136

135137
[dialog]
136138
Ok = enter

misc/mc.emacs.keymap

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ Bottom = alt-gt; end; c1
129129
# SortBySize =
130130
# SortByMTime =
131131
# Filter =
132-
# ScrollLeft =
133-
# ScrollRight =
132+
ScrollLeft = alt-lparenthesis
133+
ScrollRight = alt-rparenthesis
134+
# ScrollHome =
135+
# ScrollEnd =
134136

135137
[dialog]
136138
Ok = enter

misc/mc.vim.keymap

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ Bottom = alt-gt; end; c1
129129
# SortBySize =
130130
# SortByMTime =
131131
# Filter =
132-
# ScrollLeft =
133-
# ScrollRight =
132+
ScrollLeft = alt-lparenthesis
133+
ScrollRight = alt-rparenthesis
134+
# ScrollHome =
135+
# ScrollEnd =
134136

135137
[dialog]
136138
Ok = enter

src/filemanager/panel.c

+86-36
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <config.h>
3434

35+
#include <limits.h> // UINT_MAX
3536
#include <stdio.h>
3637
#include <stdlib.h>
3738
#include <string.h>
@@ -721,27 +722,25 @@ format_file (WPanel *panel, int file_index, int width, file_attr_t attr, gboolea
721722
if (len <= 0)
722723
break;
723724

724-
if (!isstatus && panel->content_shift > -1 && strcmp (fi->id, "name") == 0)
725+
if (!isstatus && strcmp (fi->id, "name") == 0)
725726
{
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);
728729

729730
*field_length = len + 1;
730731

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);
735733

736-
if (i > -1)
734+
if (len_diff != 0)
737735
{
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;
745744
}
746745
}
747746

@@ -758,7 +757,7 @@ format_file (WPanel *panel, int file_index, int width, file_attr_t attr, gboolea
758757
else
759758
tty_lowlevel_setcolor (-color);
760759

761-
if (!isstatus && panel->content_shift > -1)
760+
if (!isstatus)
762761
prepared_text = str_fit_to_term (txt + name_offset, len, HIDE_FIT (fi->just_mode));
763762
else
764763
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)
854853
}
855854
}
856855

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+
}
860868

861869
if ((ret_frm & FILENAME_SCROLL_RIGHT) != 0)
862870
{
863871
offset += width;
864872
if (nth_column + 1 >= panel->list_cols)
865873
offset++;
866874

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+
867880
widget_gotoyx (w, ypos, offset);
868-
tty_setcolor (NORMAL_COLOR);
881+
tty_setcolor (scroll_right_char_color);
869882
tty_print_string (panel_filename_scroll_right_char);
870883
}
871884
}
@@ -958,7 +971,7 @@ paint_dir (WPanel *panel)
958971

959972
items = panel_items (panel);
960973
// 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;
962975

963976
for (i = 0; i < items; i++)
964977
{
@@ -3194,19 +3207,16 @@ panel_select_sort_order (WPanel *panel)
31943207
}
31953208

31963209
/* --------------------------------------------------------------------------------------------- */
3197-
31983210
/**
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
32033212
*
3213+
* @param panel object
32043214
*/
32053215

32063216
static void
32073217
panel_content_scroll_left (WPanel *panel)
32083218
{
3209-
if (panel->content_shift > -1)
3219+
if (panel->content_shift != 0)
32103220
{
32113221
if (panel->content_shift > panel->max_shift)
32123222
panel->content_shift = panel->max_shift;
@@ -3219,24 +3229,58 @@ panel_content_scroll_left (WPanel *panel)
32193229

32203230
/* --------------------------------------------------------------------------------------------- */
32213231
/**
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
32263233
*
3234+
* @param panel object
32273235
*/
32283236

32293237
static void
32303238
panel_content_scroll_right (WPanel *panel)
32313239
{
3232-
if (panel->content_shift < 0 || panel->content_shift < panel->max_shift)
3240+
if (panel->content_shift == 0 || panel->content_shift < panel->max_shift)
32333241
{
32343242
panel->content_shift++;
32353243
show_dir (panel);
32363244
paint_dir (panel);
32373245
}
32383246
}
32393247

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+
32403284
/* --------------------------------------------------------------------------------------------- */
32413285

32423286
static void
@@ -3621,6 +3665,12 @@ panel_execute_cmd (WPanel *panel, long command)
36213665
case CK_ScrollRight:
36223666
panel_content_scroll_right (panel);
36233667
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;
36243674
case CK_Search:
36253675
start_search (panel);
36263676
break;
@@ -4380,8 +4430,8 @@ panel_clean_dir (WPanel *panel)
43804430
panel->quick_search.active = FALSE;
43814431
panel->is_panelized = FALSE;
43824432
panel->dirty = TRUE;
4383-
panel->content_shift = -1;
4384-
panel->max_shift = -1;
4433+
panel->content_shift = 0;
4434+
panel->max_shift = 0;
43854435

43864436
dir_list_free_list (&panel->dir);
43874437
}
@@ -4454,8 +4504,8 @@ panel_sized_empty_new (const char *panel_name, const WRect *r)
44544504
panel->list_cols = 1;
44554505
panel->brief_cols = 2;
44564506
panel->dirty = TRUE;
4457-
panel->content_shift = -1;
4458-
panel->max_shift = -1;
4507+
panel->content_shift = 0;
4508+
panel->max_shift = 0;
44594509

44604510
panel->list_format = list_full;
44614511
panel->user_format = g_strdup (DEFAULT_USER_FORMAT);

src/filemanager/panel.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ typedef struct
137137
int chpoint; // Point after last characters in @ch
138138
} quick_search;
139139

140-
int content_shift; // Number of characters of filename need to skip from left side.
141-
int max_shift; // Max shift for visible part of current panel
140+
unsigned int content_shift; // Number of characters of filename need to skip from left side
141+
unsigned int max_shift; // Max shift for visible part of current panel
142142
} WPanel;
143143

144144
/*** global variables defined in .c file *********************************************************/

0 commit comments

Comments
 (0)