Ticket #4175: CenterView_v2.patch

File CenterView_v2.patch, 3.7 KB (added by psprint, 3 years ago)
  • lib/keybind.c

    From d5979f39afb2635ec4b4b5be032f4276e85013ef Mon Sep 17 00:00:00 2001
    From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
    Date: Fri, 15 Jan 2021 12:49:25 -0600
    Subject: [PATCH] Add CenterView action to mcedit.
    
    ---
     lib/keybind.c          |  1 +
     lib/keybind.h          |  1 +
     misc/mc.default.keymap |  1 +
     src/editor/edit-impl.h |  1 +
     src/editor/edit.c      | 21 +++++++++++++++++++++
     src/keybind-defaults.c |  1 +
     6 files changed, 26 insertions(+)
    
    diff --git a/lib/keybind.c b/lib/keybind.c
    index df3cbf110..8eafcabb1 100644
    a b static name_keymap_t command_names[] = { 
    6464    ADD_KEYMAP_NAME (PageDown), 
    6565    ADD_KEYMAP_NAME (HalfPageUp), 
    6666    ADD_KEYMAP_NAME (HalfPageDown), 
     67    ADD_KEYMAP_NAME (CenterView), 
    6768    ADD_KEYMAP_NAME (Top), 
    6869    ADD_KEYMAP_NAME (Bottom), 
    6970    ADD_KEYMAP_NAME (TopOnScreen), 
  • lib/keybind.h

    diff --git a/lib/keybind.h b/lib/keybind.h
    index 817158412..453c6671b 100644
    a b enum 
    5555    CK_PageDown, 
    5656    CK_HalfPageUp, 
    5757    CK_HalfPageDown, 
     58    CK_CenterView, 
    5859    CK_Top, 
    5960    CK_Bottom, 
    6061    CK_TopOnScreen, 
  • misc/mc.default.keymap

    diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap
    index 2931ddd0a..4423424d0 100644
    a b MiddleOnScreen = alt-r 
    118118TopOnScreen = alt-g 
    119119PanelOtherSync = alt-i 
    120120SelectCodepage = alt-e 
     121CenterView = alt-shift-c 
    121122Top = alt-lt; home; a1 
    122123Bottom = alt-gt; end; c1 
    123124# Sort = 
  • src/editor/edit-impl.h

    diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h
    index 3ad04dbea..69f8c1683 100644
    a b void edit_save_size (WEdit * edit); 
    233233gboolean edit_handle_move_resize (WEdit * edit, long command); 
    234234void edit_toggle_fullscreen (WEdit * edit); 
    235235void edit_move_to_line (WEdit * e, long line); 
     236void edit_center_display (WEdit * e, long diff); 
    236237void edit_move_display (WEdit * e, long line); 
    237238void edit_word_wrap (WEdit * edit); 
    238239int edit_sort_cmd (WEdit * edit); 
  • src/editor/edit.c

    diff --git a/src/editor/edit.c b/src/editor/edit.c
    index edda1f832..2b325abfe 100644
    a b edit_move_to_line (WEdit * e, long line) 
    30223022    edit_scroll_screen_over_cursor (e); 
    30233023} 
    30243024 
     3025/* --------------------------------------------------------------------------------------------- */ 
     3026/** scroll window so that current line is in center; the diff is a relative offset from that 
     3027  * position */ 
     3028 
     3029void 
     3030edit_center_display (WEdit * e, long diff) 
     3031{ 
     3032    int center_line_diff = WIDGET (e)->lines / 2 + diff; 
     3033    int current_line = e->curs_row; 
     3034 
     3035    if (current_line < center_line_diff) 
     3036        edit_scroll_upward (e, center_line_diff - current_line); 
     3037    else 
     3038        edit_scroll_downward (e, current_line - center_line_diff); 
     3039} 
     3040 
    30253041/* --------------------------------------------------------------------------------------------- */ 
    30263042/** scroll window so that first visible line is 'line' */ 
    30273043 
    edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 
    37653781        } 
    37663782        break; 
    37673783 
     3784    case CK_CenterView: 
     3785        /* Center view at cursor line. */ 
     3786        edit_center_display (edit, 0); 
     3787        break; 
     3788 
    37683789    case CK_Top: 
    37693790    case CK_MarkToFileBegin: 
    37703791        edit_move_to_top (edit); 
  • src/keybind-defaults.c

    diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
    index 2972e5bbf..c3a8d2280 100644
    a b static const global_keymap_ini_t default_editor_keymap[] = { 
    421421    {"Goto", "alt-l; alt-shift-l"}, 
    422422    {"Refresh", "ctrl-l"}, 
    423423    {"Shell", "ctrl-o"}, 
     424    {"CenterView", "alt-shift-c"}, 
    424425    {"Top", "ctrl-home; ctrl-pgup; alt-lt"}, 
    425426    {"Bottom", "ctrl-end; ctrl-pgdn; alt-gt"}, 
    426427    {"TopOnScreen", "ctrl-pgup"},