Ticket #4175: CenterView_v3.patch

File CenterView_v3.patch, 4.1 KB (added by psprint, 4 years ago)

alt-c instead of ctrl-alt-c

  • lib/keybind.c

    From b7f010902585692326161e6e4b16fcd9a9378854 Mon Sep 17 00:00:00 2001
    From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
    Date: Sat, 23 Jan 2021 23:16:37 -0600
    Subject: CenterView action
    
    ---
     lib/keybind.c          |  1 +
     lib/keybind.h          |  1 +
     misc/mc.default.keymap |  1 +
     misc/mc.emacs.keymap   |  1 +
     src/editor/edit-impl.h |  1 +
     src/editor/edit.c      | 21 +++++++++++++++++++++
     src/keybind-defaults.c |  1 +
     7 files changed, 27 insertions(+)
    
    diff --git a/lib/keybind.c b/lib/keybind.c
    index abd44d3e2..9ab8dd5a6 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 af019df09..1cef8138d 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..fe9b5adb1 100644
    a b End = end 
    275275Tab = tab; shift-tab; ctrl-tab; ctrl-shift-tab 
    276276Undo = ctrl-u 
    277277Redo = alt-r 
     278CenterView = alt-c 
    278279Top = ctrl-home; alt-lt 
    279280Bottom = ctrl-end; alt-gt 
    280281ScrollUp = ctrl-up 
  • misc/mc.emacs.keymap

    diff --git a/misc/mc.emacs.keymap b/misc/mc.emacs.keymap
    index 7cc305db7..9d8ee0fd8 100644
    a b End = end; ctrl-e 
    275275Tab = tab; shift-tab; ctrl-tab; ctrl-shift-tab 
    276276Undo = ctrl-u 
    277277# Redo = 
     278CenterView = alt-c 
    278279Top = ctrl-home; alt-lt 
    279280Bottom = ctrl-end; alt-gt 
    280281ScrollUp = ctrl-up 
  • 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 50879cee2..9146069a2 100644
    a b edit_move_to_line (WEdit * e, long line) 
    30233023    edit_scroll_screen_over_cursor (e); 
    30243024} 
    30253025 
     3026/* --------------------------------------------------------------------------------------------- */ 
     3027/** scroll window so that current line is in center; the diff is a relative offset from that 
     3028  * position */ 
     3029 
     3030void 
     3031edit_center_display (WEdit * e, long diff) 
     3032{ 
     3033    int center_line_diff = WIDGET (e)->lines / 2 + diff; 
     3034    int current_line = e->curs_row; 
     3035 
     3036    if (current_line < center_line_diff) 
     3037        edit_scroll_upward (e, center_line_diff - current_line); 
     3038    else 
     3039        edit_scroll_downward (e, current_line - center_line_diff); 
     3040} 
     3041 
    30263042/* --------------------------------------------------------------------------------------------- */ 
    30273043/** scroll window so that first visible line is 'line' */ 
    30283044 
    edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) 
    37663782        } 
    37673783        break; 
    37683784 
     3785    case CK_CenterView: 
     3786        /* Center view at cursor line. */ 
     3787        edit_center_display (edit, 0); 
     3788        break; 
     3789 
    37693790    case CK_Top: 
    37703791    case CK_MarkToFileBegin: 
    37713792        edit_move_to_top (edit); 
  • src/keybind-defaults.c

    diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
    index 7b87c2f5a..ad4b59780 100644
    a b static const global_keymap_ini_t default_editor_keymap[] = { 
    420420    {"Goto", "alt-l; alt-shift-l"}, 
    421421    {"Refresh", "ctrl-l"}, 
    422422    {"Shell", "ctrl-o"}, 
     423    {"CenterView", "alt-c"}, 
    423424    {"Top", "ctrl-home; ctrl-pgup; alt-lt"}, 
    424425    {"Bottom", "ctrl-end; ctrl-pgdn; alt-gt"}, 
    425426    {"TopOnScreen", "ctrl-pgup"},