From 60805546bf9a1f30c24225d6e77fd60f2c440e06 Mon Sep 17 00:00:00 2001 From: Xuekun Li Date: Tue, 2 May 2023 20:52:30 +0800 Subject: [PATCH] LibGUI: Fix stuck on deleting word backward will stuck when deleting at the end of line which contains only one single character. When finding the previous word break position starting at column 0 in TextDocument::first_word_break_before, the code enters an infinite while loop. The early return should simply fix this. --- Userland/Libraries/LibGUI/TextDocument.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index 8c1b729d8f..f3e225d025 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -754,6 +754,9 @@ TextPosition TextDocument::first_word_break_before(TextPosition const& position, target.set_column(target.column() - modifier); + if (target.column() == 0) + return target; + while (target.column() < line.length()) { if (auto index = Unicode::previous_word_segmentation_boundary(line.view(), target.column()); index.has_value()) { auto view_between_target_and_index = line.view().substring_view(*index, target.column() - *index);