Anonymous avatar Anonymous committed e7bcd04

EXT-5549 Can't select last character in chat window

Comments (0)

Files changed (3)

indra/llrender/llfontgl.cpp

 	target_x *= sScaleX;
 
 	// max_chars is S32_MAX by default, so make sure we don't get overflow
-	const S32 max_index = begin_offset + llmin(S32_MAX - begin_offset, max_chars);
+	const S32 max_index = begin_offset + llmin(S32_MAX - begin_offset, max_chars - 1);
 
 	F32 scaled_max_pixels =	max_pixels * sScaleX;
 	

indra/llui/lltextbase.cpp

 					S32 segment_line_start = segmentp->getStart() + segment_offset;
 					S32 segment_line_end = llmin(segmentp->getEnd(), line_iter->mDocIndexEnd);
 
+					if (segment_line_start > segment_line_end) break;
+
 					S32 segment_width = 0;
 					S32 segment_height = 0;
 
 					}
 
 					// if selection spans end of current segment...
-					if (selection_right > segment_line_end)
+					if (selection_right >= segment_line_end)
 					{
 						// extend selection slightly beyond end of line
 						// to indicate selection of newline character (use "n" character to determine width)
 		const LLTextSegmentPtr segmentp = *line_seg_iter;
 
 		S32 segment_line_start = segmentp->getStart() + line_seg_offset;
-		S32 segment_line_length = llmin(segmentp->getEnd(), line_iter->mDocIndexEnd - 1) - segment_line_start;
+		S32 segment_line_length = llmin(segmentp->getEnd(), line_iter->mDocIndexEnd) - segment_line_start;
 		S32 text_width, text_height;
-		segmentp->getDimensions(line_seg_offset, segment_line_length, text_width, text_height);
-		if (local_x < start_x + text_width						// cursor to left of right edge of text
-			|| (hit_past_end_of_line && (segmentp->getEnd() >= line_iter->mDocIndexEnd - 1)))	// or this segment wraps to next line
+		bool newline = segmentp->getDimensions(line_seg_offset, segment_line_length, text_width, text_height);
+
+		// if we've reached a line of text *below* the mouse cursor, doc index is first character on that line
+		if (hit_past_end_of_line && local_y - mVisibleTextRect.mBottom + visible_region.mBottom > line_iter->mRect.mTop)
+		{
+			pos = segment_line_start;
+			break;
+		}
+		if (local_x < start_x + text_width			// cursor to left of right edge of text
+			|| newline)								// or this line ends with a newline, set doc pos to newline char
 		{
 			// Figure out which character we're nearest to.
 			S32 offset;
 			pos = segment_line_start + offset;
 			break;
 		}
+		else if (hit_past_end_of_line && segmentp->getEnd() >= line_iter->mDocIndexEnd - 1)	
+		{
+			// segment wraps to next line, so just set doc pos to start of next line
+			pos = llmin(getLength(), line_iter->mDocIndexEnd);
+			break;
+		}
+
 		start_x += text_width;
 	}
 

indra/newview/llchathistory.cpp

 		view->reshape(target_rect.getWidth(), view->getRect().getHeight());
 		view->setOrigin(target_rect.mLeft, view->getRect().mBottom);
 
-		std::string widget_associated_text = "[" + chat.mTimeStr + "] ";
+		std::string widget_associated_text = "\n[" + chat.mTimeStr + "] ";
 		if (utf8str_trim(chat.mFromName).size() != 0 && chat.mFromName != SYSTEM_FROM)
 			widget_associated_text += chat.mFromName + delimiter;
 
 			message = chat.mFromName + message;
 		}
 
-		message += "\n";
-		
-
 		mEditor->appendText(message, FALSE, style_params);
 	}
 	mEditor->blockUndo();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.