Fix: cursor position offset. (#562)

This resolves:
https://github.com/ArthurSonzogni/FTXUI/issues/559
This commit is contained in:
Arthur Sonzogni 2023-01-22 11:51:37 +01:00 committed by GitHub
parent 6fe8310321
commit b2853c8f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -678,23 +678,22 @@ void ScreenInteractive::Draw(Component component) {
auto document = component->Render(); auto document = component->Render();
int dimx = 0; int dimx = 0;
int dimy = 0; int dimy = 0;
auto terminal = Terminal::Size();
document->ComputeRequirement();
switch (dimension_) { switch (dimension_) {
case Dimension::Fixed: case Dimension::Fixed:
dimx = dimx_; dimx = dimx_;
dimy = dimy_; dimy = dimy_;
break; break;
case Dimension::TerminalOutput: case Dimension::TerminalOutput:
document->ComputeRequirement(); dimx = terminal.dimx;
dimx = Terminal::Size().dimx;
dimy = document->requirement().min_y; dimy = document->requirement().min_y;
break; break;
case Dimension::Fullscreen: case Dimension::Fullscreen:
dimx = Terminal::Size().dimx; dimx = terminal.dimx;
dimy = Terminal::Size().dimy; dimy = terminal.dimy;
break; break;
case Dimension::FitComponent: case Dimension::FitComponent:
auto terminal = Terminal::Size();
document->ComputeRequirement();
dimx = std::min(document->requirement().min_x, terminal.dimx); dimx = std::min(document->requirement().min_x, terminal.dimx);
dimy = std::min(document->requirement().min_y, terminal.dimy); dimy = std::min(document->requirement().min_y, terminal.dimy);
break; break;
@ -741,22 +740,14 @@ void ScreenInteractive::Draw(Component component) {
Render(*this, document); 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.
set_cursor_position = "";
reset_cursor_position = "";
{ {
const int dx = dimx_ - 1 - cursor_.x; const int dx = dimx_ - 1 - cursor_.x + int(dimx_ != terminal.dimx);
const int dy = dimy_ - 1 - cursor_.y; const int dy = dimy_ - 1 - cursor_.y;
if (dy != 0) { set_cursor_position = "\x1B[" + std::to_string(dy) + "A" + //
set_cursor_position += "\x1B[" + std::to_string(dy) + "A"; "\x1B[" + std::to_string(dx) + "D";
reset_cursor_position += "\x1B[" + std::to_string(dy) + "B"; reset_cursor_position = "\x1B[" + std::to_string(dy) + "B" + //
} "\x1B[" + std::to_string(dx) + "C";
if (dx != 0) {
set_cursor_position += "\x1B[" + std::to_string(dx) + "D";
reset_cursor_position += "\x1B[" + std::to_string(dx) + "C";
}
if (cursor_.shape == Cursor::Hidden) { if (cursor_.shape == Cursor::Hidden) {
set_cursor_position += "\033[?25l"; set_cursor_position += "\033[?25l";