textbox:paste(...) scroll fix

This commit is contained in:
MihailRis
2024-05-16 09:58:47 +03:00
parent 46e9c7dbec
commit 2bb6ad523e
2 changed files with 7 additions and 4 deletions
+5 -4
View File
@@ -132,7 +132,10 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
line++; line++;
} while (line < label->getLinesNumber() && label->isFakeLine(line)); } while (line < label->getLinesNumber() && label->isFakeLine(line));
} }
refreshLabel();
}
void TextBox::refreshLabel() {
label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f)); label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f));
label->setText(getText()); label->setText(getText());
if (multiline && font) { if (multiline && font) {
@@ -157,9 +160,7 @@ void TextBox::paste(const std::wstring& text) {
input = left + text + right; input = left + text + right;
} }
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end()); input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
// refresh label lines configuration for correct setCaret work refreshLabel();
label->setText(input);
setCaret(caret + text.length()); setCaret(caret + text.length());
validate(); validate();
} }
@@ -600,7 +601,7 @@ uint TextBox::getCaret() const {
} }
void TextBox::setCaret(uint position) { void TextBox::setCaret(uint position) {
this->caret = std::min(size_t(position), input.length()); this->caret = std::min(static_cast<size_t>(position), input.length());
caretLastMove = Window::time(); caretLastMove = Window::time();
int width = label->getSize().x; int width = label->getSize().x;
+2
View File
@@ -62,6 +62,8 @@ namespace gui {
void resetMaxLocalCaret(); void resetMaxLocalCaret();
void performEditingKeyboardEvents(keycode key); void performEditingKeyboardEvents(keycode key);
void refreshLabel();
public: public:
TextBox( TextBox(
std::wstring placeholder, std::wstring placeholder,