commit 09958ebdff1bba59837c57303fc3209e2b69b1d1
parent 53fc9a66a64ab203d1e30e1e8f62270bf1a49866
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 10 Dec 2017 21:18:06 +0100
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>
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/global.c b/src/global.c
@@ -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);
diff --git a/src/winio.c b/src/winio.c
@@ -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. */