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[] = { |
64 | 64 | ADD_KEYMAP_NAME (PageDown), |
65 | 65 | ADD_KEYMAP_NAME (HalfPageUp), |
66 | 66 | ADD_KEYMAP_NAME (HalfPageDown), |
| 67 | ADD_KEYMAP_NAME (CenterView), |
67 | 68 | ADD_KEYMAP_NAME (Top), |
68 | 69 | ADD_KEYMAP_NAME (Bottom), |
69 | 70 | ADD_KEYMAP_NAME (TopOnScreen), |
diff --git a/lib/keybind.h b/lib/keybind.h
index 817158412..453c6671b 100644
a
|
b
|
enum |
55 | 55 | CK_PageDown, |
56 | 56 | CK_HalfPageUp, |
57 | 57 | CK_HalfPageDown, |
| 58 | CK_CenterView, |
58 | 59 | CK_Top, |
59 | 60 | CK_Bottom, |
60 | 61 | CK_TopOnScreen, |
diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap
index 2931ddd0a..4423424d0 100644
a
|
b
|
MiddleOnScreen = alt-r |
118 | 118 | TopOnScreen = alt-g |
119 | 119 | PanelOtherSync = alt-i |
120 | 120 | SelectCodepage = alt-e |
| 121 | CenterView = alt-shift-c |
121 | 122 | Top = alt-lt; home; a1 |
122 | 123 | Bottom = alt-gt; end; c1 |
123 | 124 | # Sort = |
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); |
233 | 233 | gboolean edit_handle_move_resize (WEdit * edit, long command); |
234 | 234 | void edit_toggle_fullscreen (WEdit * edit); |
235 | 235 | void edit_move_to_line (WEdit * e, long line); |
| 236 | void edit_center_display (WEdit * e, long diff); |
236 | 237 | void edit_move_display (WEdit * e, long line); |
237 | 238 | void edit_word_wrap (WEdit * edit); |
238 | 239 | int edit_sort_cmd (WEdit * edit); |
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) |
3022 | 3022 | edit_scroll_screen_over_cursor (e); |
3023 | 3023 | } |
3024 | 3024 | |
| 3025 | /* --------------------------------------------------------------------------------------------- */ |
| 3026 | /** scroll window so that current line is in center; the diff is a relative offset from that |
| 3027 | * position */ |
| 3028 | |
| 3029 | void |
| 3030 | edit_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 | |
3025 | 3040 | /* --------------------------------------------------------------------------------------------- */ |
3026 | 3041 | /** scroll window so that first visible line is 'line' */ |
3027 | 3042 | |
… |
… |
edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) |
3765 | 3780 | } |
3766 | 3781 | break; |
3767 | 3782 | |
| 3783 | case CK_CenterView: |
| 3784 | /* Center view at cursor line. */ |
| 3785 | edit_center_display(edit, 0); |
| 3786 | break; |
| 3787 | |
3768 | 3788 | case CK_Top: |
3769 | 3789 | case CK_MarkToFileBegin: |
3770 | 3790 | edit_move_to_top (edit); |
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[] = { |
421 | 421 | {"Goto", "alt-l; alt-shift-l"}, |
422 | 422 | {"Refresh", "ctrl-l"}, |
423 | 423 | {"Shell", "ctrl-o"}, |
| 424 | {"CenterView", "alt-shift-c"}, |
424 | 425 | {"Top", "ctrl-home; ctrl-pgup; alt-lt"}, |
425 | 426 | {"Bottom", "ctrl-end; ctrl-pgdn; alt-gt"}, |
426 | 427 | {"TopOnScreen", "ctrl-pgup"}, |