Skip to content

Commit

Permalink
Fix pasting text when its length is matching gui element's MaxLength
Browse files Browse the repository at this point in the history
If Editbox or MultiLineEditbox have MaxTextLength set to e.g. 100 characters
then it is impossible to paste any text containing exactly 100 characters
into it.

The best moment to observe this is when user fills the control with text
until it's full, then cuts all of it and tries to paste it again.

Lua test script is available at:
https://github.com/4O4/mtasa-lua-tests/tree/master/%5Btests%5D/test-gui-limited-textbox-paste
  • Loading branch information
4O4 committed Dec 23, 2016
1 parent 8add83d commit fbc50d5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Client/gui/CGUI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,18 @@ bool CGUI_Impl::Event_KeyDown ( const CEGUI::EventArgs& Args )
CloseClipboard();
return true;
}
strEditText = WndEdit->getText ();

strEditText = WndEdit->getText();
iSelectionStart = WndEdit->getSelectionStartIndex ();
iSelectionLength = WndEdit->getSelectionLength();
iMaxLength = WndEdit->getMaxTextLength();
iCaratIndex = WndEdit->getCaratIndex();
bReplaceNewLines = false;

// Plus one character, because there is always an extra '\n' in
// MultiLineEditbox's text data and it causes MaxLength limit to
// be exceeded during pasting the text
iMaxLength += 1;
}

std::wstring strClipboardText = ClipboardBuffer;
Expand Down Expand Up @@ -901,7 +907,7 @@ bool CGUI_Impl::Event_KeyDown ( const CEGUI::EventArgs& Args )

// Put the editbox's data into a string and insert the data if it has not reached it's maximum text length
std::wstring tmp = MbUTF8ToUTF16(strEditText.c_str());
if ( ( strClipboardText.length () + tmp.length () ) < iMaxLength )
if ( ( strClipboardText.length () + tmp.length () ) <= iMaxLength )
{
// Are there characters selected?
size_t sizeCaratIndex = 0;
Expand Down

0 comments on commit fbc50d5

Please sign in to comment.