mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibGUI: Prevent selecting empty line in TextEditor on double click (#6537)
This commit is contained in:
parent
4115fcc933
commit
c41c41cc0f
Notes:
sideshowbarker
2024-07-18 19:16:47 +09:00
Author: https://github.com/Sauler 🔰 Commit: https://github.com/SerenityOS/serenity/commit/c41c41cc0f9 Pull-request: https://github.com/SerenityOS/serenity/pull/6537 Reviewed-by: https://github.com/IdanHo
3 changed files with 16 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -190,6 +190,7 @@ public:
|
|||
size_t first_non_whitespace_column() const;
|
||||
Optional<size_t> 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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue