scrolling: add a function and a key binding to center the cursor line

By default, this function is bound to ^L, to make that keystroke do
something actually useful.  To not lose the Refresh function that this
keystroke had, the centering function additionally does a full redraw
and refresh of the screen.
This commit is contained in:
Benno Schulenberg 2016-04-27 15:10:06 +02:00 committed by Benno Schulenberg
parent eb413a99f2
commit 1a2d0c1770
6 changed files with 27 additions and 2 deletions

View File

@ -1370,6 +1370,9 @@ while keeping the cursor in the same text position, if possible.
Scrolls the viewport down one row (meaning that the text slides up)
while keeping the cursor in the same text position, if possible.
@item center
Scrolls the line with the cursor to the middle of the screen.
@item prevword
Moves the cursor to the beginning of the previous word.

View File

@ -674,6 +674,9 @@ while keeping the cursor in the same text position, if possible.
Scrolls the viewport down one row (meaning that the text slides up)
while keeping the cursor in the same text position, if possible.
.TP
.B center
Scrolls the line with the cursor to the middle of the screen.
.TP
.B prevword
Moves the cursor to the beginning of the previous word.
.TP

View File

@ -622,6 +622,7 @@ void shortcut_init(void)
N_("Scroll up one line without moving the cursor textually");
const char *scrolldown_gist =
N_("Scroll down one line without moving the cursor textually");
const char *center_gist = N_("Center the line where the cursor is");
#endif
#ifdef ENABLE_MULTIBUFFER
const char *prevfile_gist = N_("Switch to the previous file buffer");
@ -1035,7 +1036,11 @@ void shortcut_init(void)
N_("Formatter"), WITHORSANS(formatter_gist), BLANKAFTER, NOVIEW);
#endif
}
#endif /* NANO_TINY */
#endif /* !NANO_TINY */
#if !defined(NANO_TINY) || defined(ENABLE_HELP)
add_to_funcs(do_center, MMAIN,
N_("Center"), WITHORSANS(center_gist), BLANKAFTER, VIEW);
#endif
add_to_funcs(do_savefile, MMAIN,
N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
@ -1322,6 +1327,9 @@ void shortcut_init(void)
#endif
#ifdef ENABLE_JUSTIFY
add_to_sclist(MEXECUTE, "^J", 0, do_full_justify, 0);
#endif
#if !defined(NANO_TINY) || defined(ENABLE_HELP)
add_to_sclist(MMAIN, "^L", 0, do_center, 0);
#endif
if (!ISSET(PRESERVE))
add_to_sclist(MMOST|MBROWSER|MHELP|MYESNO, "^L", 0, full_refresh, 0);

View File

@ -562,7 +562,15 @@ void do_scroll_down(void)
))
edit_scroll(FORWARD);
}
#endif
/* Scroll the line with the cursor to the center of the screen. */
void do_center(void)
{
adjust_viewport(CENTERING);
draw_all_subwindows();
full_refresh();
}
#endif /* !NANO_TINY || ENABLE_HELP */
/* Move left one character. */
void do_left(void)

View File

@ -386,6 +386,7 @@ void do_down(void);
#if !defined(NANO_TINY) || defined(ENABLE_HELP)
void do_scroll_up(void);
void do_scroll_down(void);
void do_center(void);
#endif
void do_left(void);
void do_right(void);

View File

@ -348,6 +348,8 @@ keystruct *strtosc(const char *input)
s->func = do_scroll_up;
else if (!strcmp(input, "scrolldown"))
s->func = do_scroll_down;
else if (!strcmp(input, "center"))
s->func = do_center;
#endif
else if (!strcmp(input, "prevword"))
s->func = to_prev_word;