input: allow using <Tab> and <Shift+Tab> to (un)indent selected region

When the mark is on, instead of letting a <Tab> simply insert a Tab
character at the cursor position, let it indent the marked region.

Original-idea-by: Chris Allegretta <chrisa@asty.org>
master
Benno Schulenberg 2017-12-10 21:18:06 +01:00
parent 53fc9a66a6
commit 09958ebdff
2 changed files with 20 additions and 1 deletions

View File

@ -1147,6 +1147,9 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0);
add_to_sclist(MMAIN, "M-}", 0, do_indent, 0);
add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0);
#ifdef KEY_BTAB
add_to_sclist(MMAIN, "S-Tab", KEY_BTAB, do_unindent, 0);
#endif
add_to_sclist(MMAIN, "M-:", 0, record_macro, 0);
add_to_sclist(MMAIN, "M-;", 0, run_macro, 0);
add_to_sclist(MMAIN, "M-U", 0, do_undo, 0);

View File

@ -621,8 +621,14 @@ int parse_kbinput(WINDOW *win)
if (console && ioctl(0, TIOCLINUX, &modifiers) >= 0) {
#ifndef NANO_TINY
/* Is Shift being held? */
if (modifiers & 0x01)
if (modifiers & 0x01) {
#ifdef KEY_BTAB
/* A shifted <Tab> is a back tab. */
if (retval == TAB_CODE)
return KEY_BTAB;
#endif
shift_held = TRUE;
}
#endif
/* Is Ctrl being held? */
if (modifiers & 0x04) {
@ -655,6 +661,16 @@ int parse_kbinput(WINDOW *win)
}
#endif /* __linux__ */
#ifndef NANO_TINY
/* When <Tab> is pressed while the mark is on, do an indent. */
if (retval == TAB_CODE && openfile->mark && currmenu == MMAIN) {
const sc *command = first_sc_for(MMAIN, do_indent);
meta_key = command->meta;
return command->keycode;
}
#endif
switch (retval) {
#ifdef KEY_SLEFT
/* Slang doesn't support KEY_SLEFT. */