Ticket #4175: CenterView.patch

File CenterView.patch, 3.7 KB (added by psprint, 8 months ago)
  • lib/keybind.c

    From 2eb4657106adaf6ba3dddb4950022c275e8dc2b8 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      | 20 ++++++++++++++++++++
     src/keybind-defaults.c |  1 +
     6 files changed, 25 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..b5bc81918 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, current_line = e->curs_row; 
     3033 
     3034    if (current_line < center_line_diff) 
     3035        edit_scroll_upward (e, center_line_diff - current_line); 
     3036    else 
     3037        edit_scroll_downward (e, current_line - center_line_diff); 
     3038} 
     3039 
    30253040/* --------------------------------------------------------------------------------------------- */ 
    30263041/** scroll window so that first visible line is 'line' */ 
    30273042 
    edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 
    37653780        } 
    37663781        break; 
    37673782 
     3783    case CK_CenterView: 
     3784        /* Center view at cursor line. */ 
     3785        edit_center_display(edit, 0); 
     3786        break; 
     3787 
    37683788    case CK_Top: 
    37693789    case CK_MarkToFileBegin: 
    37703790        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"},