It somewhat works

This commit is contained in:
Clement Roblot 2024-08-27 21:13:00 +07:00 committed by ArthurSonzogni
parent cb2436f13f
commit 2339ead35c
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
3 changed files with 22 additions and 8 deletions

View File

@ -69,7 +69,7 @@ int main() {
text("Your phone number is " + phoneNumber),
// text("select_start " + std::to_string(selection.startx) + ";" + std::to_string(selection.starty)),
// text("select_end " + std::to_string(selection.endx) + ";" + std::to_string(selection.endy)),
text("textToCopy " + textToCopy)
text("textToCopy is " + textToCopy)
}) |
border; // | selectable([&textToCopy](std::string txtSelected){textToCopy = txtSelected;})
});

View File

@ -139,6 +139,7 @@ class ScreenInteractive : public Screen {
bool force_handle_ctrl_z_ = true;
Region selectedRegion;
std::string selectedText;
// The style of the cursor to restore on exit.
int cursor_reset_shape_ = 1;

View File

@ -357,7 +357,8 @@ ScreenInteractive::ScreenInteractive(int dimx,
bool use_alternative_screen)
: Screen(dimx, dimy),
dimension_(dimension),
use_alternative_screen_(use_alternative_screen) {
use_alternative_screen_(use_alternative_screen),
selectedText("") {
task_receiver_ = MakeReceiver<Task>();
}
@ -853,15 +854,15 @@ bool ScreenInteractive::selectableCatchEvent(Event event) {
selectedRegion.starty = mouse.y;
selectedRegion.endx = mouse.x;
selectedRegion.endy = mouse.y;
refreshSelection();
// refreshSelection();
} else if (mouse.motion == Mouse::Released) {
selectedRegion.endx = mouse.x;
selectedRegion.endy = mouse.y;
refreshSelection();
// refreshSelection();
} else if (mouse.motion == Mouse::Moved) {
selectedRegion.endx = mouse.x;
selectedRegion.endy = mouse.y;
refreshSelection();
// refreshSelection();
}
}
}
@ -871,16 +872,26 @@ bool ScreenInteractive::selectableCatchEvent(Event event) {
void ScreenInteractive::refreshSelection(void) {
selectedText = "";
for (int y = std::min(selectedRegion.starty, selectedRegion.endy); y <= std::max(selectedRegion.starty, selectedRegion.endy); ++y) {
for (int x = std::min(selectedRegion.startx, selectedRegion.endx); x <= std::max(selectedRegion.startx, selectedRegion.endx)-1; ++x) {
PixelAt(x, y).inverted ^= true;
//selectedText += PixelAt(x, y).character;
if(PixelAt(x, y).selectable == true)
{
PixelAt(x, y).inverted ^= true;
selectedText += PixelAt(x, y).character;
}
}
}
}
std::string ScreenInteractive::getSelection(void) {
return "Kikoo";
// std::ofstream MyFile("debug.log", std::ios_base::app);
// MyFile << "Top dog!" << std::endl;
// MyFile.close();
return selectedText;
}
// private
@ -960,6 +971,8 @@ void ScreenInteractive::Draw(Component component) {
Render(*this, document);
refreshSelection();
// Set cursor position for user using tools to insert CJK characters.
{
const int dx = dimx_ - 1 - cursor_.x + int(dimx_ != terminal.dimx);