From bd9978e4678ab49ebafec0a22ba3329ce1b6236d Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Mon, 26 Jun 2023 23:52:23 +0200 Subject: [PATCH] core: check for newline characters in string_is_whitespace_char This fixes a bug where if you had multiple lines in the input and pressed ctrl-w when the cursor was after the first word of any line but the first, it would delete both the word before the cursor and the last word on the preceding line. --- src/core/wee-string.c | 8 ++++++-- tests/unit/core/test-core-string.cpp | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 2f6a7b3e8..83ee9e63c 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -1312,7 +1312,7 @@ string_convert_escaped_chars (const char *string) } /* - * Checks if first char of string is a whitespace (space or tab). + * Checks if first char of string is a whitespace (space, tab, newline or carriage return). * * Returns: * 1: first char is whitespace @@ -1322,7 +1322,11 @@ string_convert_escaped_chars (const char *string) int string_is_whitespace_char (const char *string) { - return (string && ((string[0] == ' ') || string[0] == '\t')) ? 1 : 0; + return (string && ( + (string[0] == ' ') + || (string[0] == '\t') + || (string[0] == '\n') + || (string[0] == '\r'))) ? 1 : 0; } /* diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 876e71c0a..465276c66 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -1090,6 +1090,8 @@ TEST(CoreString, IsWhitespaceChar) LONGS_EQUAL(1, string_is_whitespace_char (" abc def")); LONGS_EQUAL(1, string_is_whitespace_char ("\tabc def")); + LONGS_EQUAL(1, string_is_whitespace_char ("\nabc def")); + LONGS_EQUAL(1, string_is_whitespace_char ("\rabc def")); } /*