diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index afb9fd3c6..bdad12760 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -206,6 +206,29 @@ void Textbox::pasteIntoSelection() *iter = '0'; } } + + int regionWidth = Size.X; + if(Appearance.icon) + regionWidth -= 13; + regionWidth -= Appearance.Margin.Left; + regionWidth -= Appearance.Margin.Right; + + if(limit!=std::string::npos) + { + if(limit-backingText.length() > 0) + newText.substr(0, limit-backingText.length()); + } + else if(Graphics::textwidth((char*)std::string(backingText+newText).c_str()) > regionWidth) + { + int pLimit = regionWidth - Graphics::textwidth((char*)backingText.c_str()); + int cIndex = Graphics::CharIndexAtPosition((char *)newText.c_str(), pLimit, 0); + + if(cIndex > 0) + newText = newText.substr(0, cIndex); + else + newText = ""; + } + backingText.insert(cursor, newText); cursor = cursor+newText.length(); ClearSelection();