commit 918ce1afa3c6e9dec1bc5f17fe9bbe93a9e1ebfe
parent 5d285ca896f7954d3019dd7f55ed11b32d739f84
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 21 Oct 2021 11:56:22 +0200
tweaks: just let do_wrap() set 'refresh_needed' instead of returning TRUE
This gets rid of performing an action in the condition of an 'if'.
Diffstat:
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -1465,9 +1465,8 @@ void inject(char *burst, size_t count)
#endif
#ifdef ENABLE_WRAPPING
- /* Wrap the line when needed, and if so, schedule a refresh. */
- if (ISSET(BREAK_LONG_LINES) && do_wrap())
- refresh_needed = TRUE;
+ if (ISSET(BREAK_LONG_LINES))
+ do_wrap();
#endif
#ifndef NANO_TINY
diff --git a/src/prototypes.h b/src/prototypes.h
@@ -493,7 +493,7 @@ void update_multiline_undo(ssize_t lineno, char *indentation);
void update_undo(undo_type action);
#endif /* !NANO_TINY */
#ifdef ENABLE_WRAPPING
-bool do_wrap(void);
+void do_wrap(void);
#endif
#if defined(ENABLE_HELP) || defined(ENABLED_WRAPORJUSTIFY)
ssize_t break_line(const char *textstart, ssize_t goal, bool snap_at_nl);
diff --git a/src/text.c b/src/text.c
@@ -1212,9 +1212,9 @@ void update_undo(undo_type action)
#ifdef ENABLE_WRAPPING
/* When the current line is overlong, hard-wrap it at the furthest possible
- * whitespace character, and (if possible) prepend the remainder of the line
- * to the next line. Return TRUE if wrapping occurred, and FALSE otherwise. */
-bool do_wrap(void)
+ * whitespace character, and prepend the excess part to an "overflow" line
+ * (when it already exists, otherwise create one). */
+void do_wrap(void)
{
linestruct *line = openfile->current;
/* The line to be wrapped, if needed and possible. */
@@ -1243,7 +1243,7 @@ bool do_wrap(void)
/* If no wrapping point was found before end-of-line, we don't wrap. */
if (wrap_loc < 0 || lead_len + wrap_loc == line_len)
- return FALSE;
+ return;
/* Adjust the wrap location to its position in the full line,
* and step forward to the character just after the blank. */
@@ -1251,7 +1251,7 @@ bool do_wrap(void)
/* When now at end-of-line, no need to wrap. */
if (line->data[wrap_loc] == '\0')
- return FALSE;
+ return;
#ifndef NANO_TINY
add_undo(SPLIT_BEGIN, NULL);
@@ -1360,7 +1360,7 @@ bool do_wrap(void)
add_undo(SPLIT_END, NULL);
#endif
- return TRUE;
+ refresh_needed = TRUE;
}
#endif /* ENABLE_WRAPPING */