From c8addf1a5ecf6c0806ae6a55cad4895417b05138 Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Wed, 5 Jan 2022 10:21:57 +1100 Subject: [PATCH] LibGUI: Consume initial spaces when going to next/prev word break This impacts text editors' ctrl+left, ctrl+shift+right, ctrl+backspace, etc.. For example, consider the text "Hello world |", pressing ctrl+backspace each time. Before: "hello world |" "hello world|" "hello |" "hello|" "|" After: "hello world |" "hello|" "|" Note that this breaks a nice symmetry. Doing ctrl+left and then ctrl+right doesn't necessarily get you to the same place like it use to. Before: " hello |" " hello| " " hello |" // same as initial After: " hello |" "|hello " " hello| " // different from initial --- Userland/Libraries/LibGUI/TextDocument.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index 7982b06d29..12be654774 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -654,6 +654,8 @@ TextPosition TextDocument::first_word_break_before(const TextPosition& position, if (target.column() == line.length()) modifier = 1; + while (target.column() > 0 && is_ascii_blank(line.code_points()[target.column() - modifier])) + target.set_column(target.column() - 1); auto is_start_alphanumeric = is_ascii_alphanumeric(line.code_points()[target.column() - modifier]); while (target.column() > 0) { @@ -678,6 +680,8 @@ TextPosition TextDocument::first_word_break_after(const TextPosition& position) return TextPosition(position.line() + 1, 0); } + while (target.column() < line.length() && is_ascii_space(line.code_points()[target.column()])) + target.set_column(target.column() + 1); auto is_start_alphanumeric = is_ascii_alphanumeric(line.code_points()[target.column()]); while (target.column() < line.length()) {