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
This commit is contained in:
Mathieu PATUREL 2022-01-05 10:21:57 +11:00 committed by Andreas Kling
parent 4b4cf06069
commit c8addf1a5e
Notes: sideshowbarker 2024-07-17 21:35:48 +09:00

View file

@ -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()) {