- if(start == end) {
- wordidx = start;
- if(wordidx > 0) {
- const ChatLineModel::Word &prevWord = wrapList.at(wordidx - 1);
- choppedTrailing += prevWord.trailing - (targetWidth - prevWord.endX);
- }
+ if(start + 1 == end) {
+ wordidx = end;
+ const ChatLineModel::Word &lastWord = wrapList.at(start); // the last word we were able to squeeze in
+
+ // both cases should be cought preliminary
+ Q_ASSERT(lastWord.endX <= targetWidth); // ensure that "start" really fits in
+ Q_ASSERT(end < wrapList.count()); // ensure that start isn't the last word
+
+ choppedTrailing += lastWord.trailing - (targetWidth - lastWord.endX);