From a172a9689783bed4d1fdfa8887f9f4be881b7076 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 13:17:29 -0500 Subject: [PATCH] make sure long amounts of text without spaces doesn't run over out of bounds A character may be deleted to insert a new line, but when copying something like a url, the missing one is copied back in. I couldn't get inserting a newline between letters to work right --- src/interface/Label.cpp | 42 ++++++++++++++++++++------------------- src/interface/Textbox.cpp | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp index 80387cebc..5cd089c18 100644 --- a/src/interface/Label.cpp +++ b/src/interface/Label.cpp @@ -96,23 +96,30 @@ void Label::updateMultiline() lines++; break; default: - if(pc == ' ') - { - wordStart = &rawText[charIndex-2]; - } wordWidth += Graphics::CharWidth(c); - if(lineWidth + wordWidth >= Size.X-(Appearance.Margin.Left+Appearance.Margin.Right)) - { - if(wordStart && *wordStart) - *wordStart = '\n'; - else if(!wordStart) - rawText[charIndex-1] = '\n'; - lineWidth = wordWidth; - wordWidth = 0; - lines++; - } break; } + if(pc == ' ') + { + wordStart = &rawText[charIndex-2]; + } + if ((c != ' ' || pc == ' ') && lineWidth + wordWidth >= Size.X-(Appearance.Margin.Left+Appearance.Margin.Right)) + { + if(wordStart && *wordStart) + { + *wordStart = '\n'; + if (lineWidth != 0) + lineWidth = wordWidth; + } + else if(!wordStart) + { + rawText[charIndex-1] = '\n'; + lineWidth = 0; + } + wordWidth = 0; + wordStart = 0; + lines++; + } pc = c; } if(autoHeight) @@ -201,12 +208,7 @@ void Label::OnMouseClick(int x, int y, unsigned button) void Label::copySelection() { - std::string currentText; - - if(multiline) - currentText = textLines; - else - currentText = text; + std::string currentText = text; if(selectionIndex1 > selectionIndex0) { clipboard_push_text((char*)currentText.substr(selectionIndex0, selectionIndex1-selectionIndex0).c_str()); diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 383f07b6e..c82b6e417 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -447,7 +447,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool backingText.erase(backingText.begin()); } if(cursor > backingText.length()) - cursor = backingText.length(); + cursor = backingText.length(); if(changed) { if(masked)