From 46f7fbb8dc506884ebf5e4803acec270bb912204 Mon Sep 17 00:00:00 2001 From: Clement Roblot Date: Tue, 26 Nov 2024 17:13:40 +0700 Subject: [PATCH] Easier to read HandleSelection --- src/ftxui/component/screen_interactive.cpp | 52 ++++++++++------------ 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 1f856f1..8cfa7e0 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -837,37 +837,31 @@ bool ScreenInteractive::HandleSelection(Event event) { return false; } - if (mouse.motion == Mouse::Pressed) { - selection_pending_ = CaptureMouse(); - if (!selection_pending_) { - return false; - } - selection_enabled_ = true; - selection_box_.x_min = mouse.x; - selection_box_.y_min = mouse.y; - selection_box_.x_max = mouse.x; - selection_box_.y_max = mouse.y; - return true; + if(mouse.motion == Mouse::Pressed) { + selection_pending_ = CaptureMouse(); + if (!selection_pending_) { + return false; + } + selection_enabled_ = true; + selection_box_.x_min = mouse.x; + selection_box_.y_min = mouse.y; + selection_box_.x_max = mouse.x; + selection_box_.y_max = mouse.y; + return true; + } + else if((mouse.motion == Mouse::Moved) && (selection_pending_)) { + selection_box_.x_max = mouse.x; + selection_box_.y_max = mouse.y; + return true; + } + else if((mouse.motion == Mouse::Released) && (selection_pending_)) { + selection_box_.x_max = mouse.x; + selection_box_.y_max = mouse.y; + selection_pending_ = nullptr; + return true; } - if (!selection_pending_) { - return false; - } - - if (mouse.motion == Mouse::Moved) { - selection_box_.x_max = mouse.x; - selection_box_.y_max = mouse.y; - return true; - } - - if (mouse.motion != Mouse::Released) { - return false; - } - - selection_box_.x_max = mouse.x; - selection_box_.y_max = mouse.y; - selection_pending_ = nullptr; - return true; + return false; } // private