Implementation of the selection in the text node

This commit is contained in:
Clement Roblot 2024-10-31 21:05:39 +07:00 committed by ArthurSonzogni
parent 011b9a1426
commit 23a8c94bef
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
2 changed files with 12 additions and 21 deletions

View File

@ -877,25 +877,6 @@ bool ScreenInteractive::HandleSelection(Event event) {
return false; return false;
} }
void ScreenInteractive::RefreshSelection() {
if (!selection_enabled) {
return;
}
selection_text = "";
for (int y = std::min(selection_region.y_min, selection_region.y_max);
y <= std::max(selection_region.y_min, selection_region.y_max); ++y) {
for (int x = std::min(selection_region.x_min, selection_region.x_max);
x <= std::max(selection_region.x_min, selection_region.x_max) - 1;
++x) {
if (PixelAt(x, y).selectable == true) {
PixelAt(x, y).inverted ^= true;
selection_text += PixelAt(x, y).character;
}
}
}
}
std::string ScreenInteractive::GetSelection() { std::string ScreenInteractive::GetSelection() {
return selection_text; return selection_text;
} }
@ -975,9 +956,10 @@ void ScreenInteractive::Draw(Component component) {
#endif #endif
previous_frame_resized_ = resized; previous_frame_resized_ = resized;
Render(*this, document); // Clear selection text.
selection_text = "";
RefreshSelection(); Render(*this, document);
// Set cursor position for user using tools to insert CJK characters. // Set cursor position for user using tools to insert CJK characters.
{ {

View File

@ -42,6 +42,15 @@ class Text : public Node {
continue; continue;
} }
screen.PixelAt(x, y).character = cell; screen.PixelAt(x, y).character = cell;
if(screen.PixelAt(x, y).selectable == true)
{
if(screen.selection_region.Contain(x, y)) {
screen.PixelAt(x, y).inverted ^= true;
screen.selection_text += screen.PixelAt(x, y).character;
}
}
++x; ++x;
} }
} }