From 9ac30381faf07f298e88ee777cbc6748b68a5cab Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Tue, 12 May 2020 23:06:39 +0200 Subject: core: Implement commands for operating on a single input line This changes the commands delete_beginning_of_line, delete_end_of_line, delete_line, move_beginning_of_line and move_end_of_line to operate on the current line instead of the whole input. The commands delete_beginning_of_input, delete_end_of_input, delete_input, move_beginning_of_input and move_end_of_input are added with the previous implementations that the line commands had. Additionally, the commands move_previous_line and move_next_line are added which moves the cursor to the previous/next line and keeps the horizontal position in the line. The meta-r key is changed from delete_line to delete_input to keep the behavior, and because you probably want to delete the whole input more often than the line. The meta-R key is added for delete_line. The home, end, ctrl-u and ctrl-k keys are kept to the same commands, which means that they change behaviour. This is because having them operate on the line is consistent with other applications (vim, zsh), and I also think it's more practical. These new bindings are added: shift-home: /input move_beginning_of_input shift-end: /input move_end_of_input shift-up: /input move_previous_line shift-down: /input move_next_line meta-R: /input delete_line meta-ctrl-u: /input delete_beginning_of_input meta-ctrl-k: /input delete_end_of_input Relates to #1498 --- tests/unit/core/test-core-utf8.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'tests/unit/core') diff --git a/tests/unit/core/test-core-utf8.cpp b/tests/unit/core/test-core-utf8.cpp index 389344a55..89615a9c0 100644 --- a/tests/unit/core/test-core-utf8.cpp +++ b/tests/unit/core/test-core-utf8.cpp @@ -114,11 +114,12 @@ extern "C" #define UTF8_4BYTES_TRUNCATED_3 "\xf0\xa4\xad" /* "noël" */ -#define UTF8_NOEL_VALID "no\xc3\xabl" -#define UTF8_NOEL_INVALID "no\xc3l" -#define UTF8_NOEL_INVALID2 "no\xff\xffl" -#define UTF8_NOEL_INVALID_NORM "no?l" -#define UTF8_NOEL_INVALID2_NORM "no??l" +#define UTF8_NOEL_VALID "no\xc3\xabl" +#define UTF8_NOEL_VALID_MULTILINE "no\xc3\xabl\nno\xc3\xabl" +#define UTF8_NOEL_INVALID "no\xc3l" +#define UTF8_NOEL_INVALID2 "no\xff\xffl" +#define UTF8_NOEL_INVALID_NORM "no?l" +#define UTF8_NOEL_INVALID2_NORM "no??l" TEST_GROUP(CoreUtf8) { @@ -323,6 +324,8 @@ TEST(CoreUtf8, Normalize) * Tests functions: * utf8_prev_char * utf8_next_char + * utf8_beginning_of_line + * utf8_end_of_line * utf8_add_offset * utf8_real_pos * utf8_pos @@ -333,6 +336,7 @@ TEST(CoreUtf8, Move) const char *ptr; const char *empty_string = ""; const char *noel_valid = UTF8_NOEL_VALID; + const char *noel_valid_multiline = UTF8_NOEL_VALID_MULTILINE; const char *utf8_2bytes_truncated_1 = UTF8_2BYTES_TRUNCATED_1; const char *utf8_3bytes_truncated_1 = UTF8_3BYTES_TRUNCATED_1; const char *utf8_3bytes_truncated_2 = UTF8_3BYTES_TRUNCATED_2; @@ -377,6 +381,28 @@ TEST(CoreUtf8, Move) POINTERS_EQUAL(utf8_4bytes_truncated_3 + 3, utf8_next_char (utf8_4bytes_truncated_3)); + /* beginning/end of line */ + POINTERS_EQUAL(NULL, utf8_beginning_of_line (NULL, NULL)); + POINTERS_EQUAL(NULL, utf8_end_of_line (NULL)); + ptr = utf8_end_of_line (noel_valid_multiline); + STRCMP_EQUAL("\nnoël", ptr); + ptr = utf8_end_of_line (ptr); + STRCMP_EQUAL("\nnoël", ptr); + ptr = utf8_next_char (ptr); + ptr = utf8_end_of_line (ptr); + STRCMP_EQUAL("", ptr); + ptr = utf8_end_of_line (ptr); + STRCMP_EQUAL("", ptr); + ptr = utf8_beginning_of_line (noel_valid_multiline, ptr); + STRCMP_EQUAL(noel_valid, ptr); + ptr = utf8_beginning_of_line (noel_valid_multiline, ptr); + STRCMP_EQUAL(noel_valid, ptr); + ptr = utf8_prev_char (noel_valid_multiline, ptr); + ptr = utf8_beginning_of_line (noel_valid_multiline, ptr); + STRCMP_EQUAL(noel_valid_multiline, ptr); + ptr = utf8_beginning_of_line (noel_valid_multiline, ptr); + STRCMP_EQUAL(noel_valid_multiline, ptr); + /* add offset */ POINTERS_EQUAL(NULL, utf8_add_offset (NULL, 0)); ptr = utf8_add_offset (noel_valid, 0); -- cgit v1.2.3