diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index d7753c5808..2aa1cd8cb7 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -141,6 +141,18 @@ bool TextDocumentLine::ends_in_whitespace() const return isspace(code_points()[length() - 1]); } +bool TextDocumentLine::can_select() const +{ + if (is_empty()) + return false; + for (size_t i = 0; i < length(); ++i) { + auto code_point = code_points()[i]; + if (code_point != '\n' && code_point != '\r' && code_point != '\f' && code_point != '\v') + return true; + } + return false; +} + size_t TextDocumentLine::leading_spaces() const { size_t count = 0; diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h index 8affc92d81..50db31d5bf 100644 --- a/Userland/Libraries/LibGUI/TextDocument.h +++ b/Userland/Libraries/LibGUI/TextDocument.h @@ -190,6 +190,7 @@ public: size_t first_non_whitespace_column() const; Optional last_non_whitespace_column() const; bool ends_in_whitespace() const; + bool can_select() const; bool is_empty() const { return length() == 0; } size_t leading_spaces() const; diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index ea5cddef47..1bd2bd5bcd 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -228,6 +228,9 @@ void TextEditor::doubleclick_event(MouseEvent& event) if (is_displayonly()) return; + if (!current_line().can_select()) + return; + // NOTE: This ensures that spans are updated before we look at them. flush_pending_change_notification_if_needed();