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[] = { |
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 af019df09..1cef8138d 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..fe9b5adb1 100644
a
|
b
|
End = end |
275 | 275 | Tab = tab; shift-tab; ctrl-tab; ctrl-shift-tab |
276 | 276 | Undo = ctrl-u |
277 | 277 | Redo = alt-r |
| 278 | CenterView = alt-c |
278 | 279 | Top = ctrl-home; alt-lt |
279 | 280 | Bottom = ctrl-end; alt-gt |
280 | 281 | ScrollUp = ctrl-up |
diff --git a/misc/mc.emacs.keymap b/misc/mc.emacs.keymap
index 7cc305db7..9d8ee0fd8 100644
a
|
b
|
End = end; ctrl-e |
275 | 275 | Tab = tab; shift-tab; ctrl-tab; ctrl-shift-tab |
276 | 276 | Undo = ctrl-u |
277 | 277 | # Redo = |
| 278 | CenterView = alt-c |
278 | 279 | Top = ctrl-home; alt-lt |
279 | 280 | Bottom = ctrl-end; alt-gt |
280 | 281 | ScrollUp = ctrl-up |
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 50879cee2..9146069a2 100644
a
|
b
|
edit_move_to_line (WEdit * e, long line) |
3023 | 3023 | edit_scroll_screen_over_cursor (e); |
3024 | 3024 | } |
3025 | 3025 | |
| 3026 | /* --------------------------------------------------------------------------------------------- */ |
| 3027 | /** scroll window so that current line is in center; the diff is a relative offset from that |
| 3028 | * position */ |
| 3029 | |
| 3030 | void |
| 3031 | edit_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 | |
3026 | 3042 | /* --------------------------------------------------------------------------------------------- */ |
3027 | 3043 | /** scroll window so that first visible line is 'line' */ |
3028 | 3044 | |
… |
… |
edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) |
3766 | 3782 | } |
3767 | 3783 | break; |
3768 | 3784 | |
| 3785 | case CK_CenterView: |
| 3786 | /* Center view at cursor line. */ |
| 3787 | edit_center_display (edit, 0); |
| 3788 | break; |
| 3789 | |
3769 | 3790 | case CK_Top: |
3770 | 3791 | case CK_MarkToFileBegin: |
3771 | 3792 | edit_move_to_top (edit); |
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[] = { |
420 | 420 | {"Goto", "alt-l; alt-shift-l"}, |
421 | 421 | {"Refresh", "ctrl-l"}, |
422 | 422 | {"Shell", "ctrl-o"}, |
| 423 | {"CenterView", "alt-c"}, |
423 | 424 | {"Top", "ctrl-home; ctrl-pgup; alt-lt"}, |
424 | 425 | {"Bottom", "ctrl-end; ctrl-pgdn; alt-gt"}, |
425 | 426 | {"TopOnScreen", "ctrl-pgup"}, |