Ver Fonte

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
Mathieu PATUREL há 3 anos atrás
pai
commit
c8addf1a5e
1 ficheiros alterados com 4 adições e 0 exclusões
  1. 4 0
      Userland/Libraries/LibGUI/TextDocument.cpp

+ 4 - 0
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()) {