Skip to content

Commit

Permalink
Merge pull request #101 from 4O4/bugfix/gui-textboxes-paste-handling
Browse files Browse the repository at this point in the history
Better handling of text pasting in GUI textboxes
  • Loading branch information
qaisjp committed Dec 28, 2016
2 parents d97bf8f + cda09b4 commit 0537ea0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Client/gui/CGUI_Impl.cpp
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 () - iSelectionLength ) <= iMaxLength )
{
// Are there characters selected?
size_t sizeCaratIndex = 0;
Expand Down

0 comments on commit 0537ea0

Please sign in to comment.