[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] input: suppress auto-indenting when the keyboard gets flooded
From: |
Benno Schulenberg |
Subject: |
[PATCH] input: suppress auto-indenting when the keyboard gets flooded |
Date: |
Mon, 6 Jan 2020 20:08:55 +0100 |
---
src/proto.h | 1 +
src/text.c | 4 ++--
src/winio.c | 13 +++++++++++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/proto.h b/src/proto.h
index 682538b1..d062ce8d 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -603,6 +603,7 @@ linestruct *line_from_number(ssize_t lineno);
void record_macro(void);
void run_macro(void);
size_t get_key_buffer_len(void);
+bool repress_autoindenting(void);
void put_back(int keycode);
void unget_kbinput(int kbinput, bool metakey);
#ifdef ENABLE_NANORC
diff --git a/src/text.c b/src/text.c
index 118d9994..7b0520dc 100644
--- a/src/text.c
+++ b/src/text.c
@@ -853,7 +853,7 @@ void do_enter(void)
linestruct *sampleline = openfile->current;
bool allblanks = FALSE;
- if (ISSET(AUTOINDENT)) {
+ if (ISSET(AUTOINDENT) && !repress_autoindenting()) {
#ifdef ENABLE_JUSTIFY
/* When doing automatic long-line wrapping and the next line is
* in this same paragraph, use its indentation as the model. */
@@ -875,7 +875,7 @@ void do_enter(void)
strcpy(&newnode->data[extra], openfile->current->data +
openfile->current_x);
#ifndef NANO_TINY
- if (ISSET(AUTOINDENT)) {
+ if (ISSET(AUTOINDENT) && !repress_autoindenting()) {
/* Copy the whitespace from the sample line to the new one. */
strncpy(newnode->data, sampleline->data, extra);
/* If there were only blanks before the cursor, trim them. */
diff --git a/src/winio.c b/src/winio.c
index 43925289..78c7f6a0 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -260,6 +260,19 @@ size_t get_key_buffer_len(void)
return key_buffer_len;
}
+/* Return TRUE when auto-indenting needs to be suppressed: when more than one
+ * character is waiting in the keyboard buffer and the first is whitespace.
+ * The suppression is switched back off when the buffer becomes empty. */
+bool repress_autoindenting(void)
+{
+ static bool repression = FALSE;
+
+ repression |= (key_buffer_len > 1 && (*key_buffer == 0x20 ||
*key_buffer == 0x09));
+ repression &= (key_buffer_len > 0);
+
+ return repression;
+}
+
/* Add the given keycode to the front of the keystroke buffer. */
void put_back(int keycode)
{
--
2.24.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] input: suppress auto-indenting when the keyboard gets flooded,
Benno Schulenberg <=