Ticket #3130 (closed enhancement: fixed)

Opened 3 years ago

Last modified 12 months ago

Panel Scroll Center

Reported by: Miven Owned by: andrew_b
Priority: minor Milestone: 4.8.17
Component: mc-core Version: master
Keywords: Cc: gotar@…, mooffie@…
Blocked By: Blocking:
Branch state: merged Votes for changeset: committed-master

Description

This patch adds an option, Center &scrolling, to the panel options dialog.

Behavior: This patch causes the panel to begin scrolling when the cursor reaches the middle of the panel, so that the cursor *tends* to stay in the middle of the panel on long listings. Only when you reach the beginning or the end of the listing will the cursor move to the first or last file.

Included is a patch for 5 files:
doc/man/mc.1.in
src/setup.h
src/setup.c
src/filemanager/boxes.c
src/filemanager/panel.c

These were diffed from the latest git repo of 4.8.11.

Attachments

patch-panel-scroll-center.diff (4.0 KB) - added by Miven 3 years ago.
panel-scroll-center diff

Change History

Changed 3 years ago by Miven

panel-scroll-center diff

comment:1 Changed 3 years ago by gotar

  • Cc gotar@… added

This would be a great feature - I've thought about this many times (and forgot to create feature request), but extended to allow setting some boundaries (range) that selection could move inside before scrolling.

comment:2 Changed 2 years ago by mooffie

  • Cc mooffie@… added

comment:3 Changed 2 years ago by andrew_b

  • Keywords panel scroll center removed
  • Blocked By 3212 added

comment:4 Changed 2 years ago by andrew_b

  • Blocked By 3212 removed

comment:5 Changed 12 months ago by andrew_b

  • Status changed from new to accepted
  • Owner set to andrew_b
  • Branch state changed from no branch to on review
  • Milestone changed from Future Releases to 4.8.17

Branch: 3130_panel_center_scroll.
Initial changeset:f6306f2c98b5a3de04d3d6b1569c3e1cc1d78ad7

comment:6 follow-up: ↓ 7 Changed 12 months ago by zaytsev

I'm a bit bothered by the copy-paste under /* define top file of column */ :-/ Too bad C doesn't have lambdas. Do you think it's worth it extracting into a small function?

comment:7 in reply to: ↑ 6 Changed 12 months ago by andrew_b

Replying to zaytsev:

Do you think it's worth it extracting into a small function?

Lets's consider two cases.

1.

static int
panel_get_top_file_at_column (const WPanel * panel)
{
    int lines, top;

    lines = panel_lines (panel);

    top = panel->top_file;
    if (panel->list_cols > 1)
        top += lines * ((panel->selected - top) / lines);

    return top;
}

In this case lines is required twice: inside and outsize panel_get_top_file_at_column(). Thus, lines is calculated twice.

2.

static int
panel_get_top_file_at_column (const WPanel * panel, int lines)
{
    int top;

    top = panel->top_file;
    if (panel->list_cols > 1)
        top += lines * ((panel->selected - top) / lines);

    return top;
}

In this case lines is calculated once and passed into panel_get_top_file_at_column(). This looks like lines and panel are not matched but is not true.

Both cases are bad in my view.

comment:8 follow-up: ↓ 9 Changed 12 months ago by zaytsev

So, how about the following code:

static int
i_cant_think_of_a_good_name_because_im_tired (const WPanel * panel)
{
    int lines, top;

    lines = panel_lines (panel);

    top = panel->top_file;
    if (panel->list_cols > 1)
        top += lines * ((panel->selected - top) / lines);

    return (panel->selected - top) - (lines / 2);
}

...


/* Scroll window when cursor is halfway down */ 
if ( i_cant_think_of_a_good_name_because_im_tired(panel) > 0) 
{ 
    panel->top_file++; 
    if (panel->top_file > panel->dir.len - items) 
        panel->top_file = panel->dir.len - items; 
}

...

/* Scroll window when cursor is halfway up */ 
if ( i_cant_think_of_a_good_name_because_im_tired(panel) < 0) 
{ 
    panel->top_file--; 
    if (panel->top_file < 0) 
        panel->top_file = 0; 
}

I must be certainly missing something (apart from a good name for the function, my brain is completely burned out now)...

comment:9 in reply to: ↑ 8 Changed 12 months ago by andrew_b

Replying to zaytsev:

So, how about the following code:

Great! I added the fixup changeset:df62684006ec11e18e937bc19d33e781de7d1715
The better name of function is welcome!

comment:10 Changed 12 months ago by zaytsev

  • Branch state changed from on review to approved

The better name of function is welcome!

I would say maybe "panel_selected_relative_to_middle", but that's quite long. Everything looks good!

comment:11 Changed 12 months ago by andrew_b

  • Status changed from accepted to testing
  • Votes for changeset set to committed-master
  • Resolution set to fixed
  • Branch state changed from approved to merged

Merged to master: [4b142c7637af7ef206cb1b02655cdbb352aab3b6].

git log --pretty=oneline 82fc95f..4b142c7

comment:12 Changed 12 months ago by andrew_b

  • Status changed from testing to closed
Note: See TracTickets for help on using tickets.