Răsfoiți Sursa

Fixes UITextInput::getSelectionText()

Fixes issue #186

There were some semantical errors with its implementation. Rewrote most of the function using a more concise and intuitive algorithm.
cib 13 ani în urmă
părinte
comite
7e790bffb8
1 a modificat fișierele cu 13 adăugiri și 17 ștergeri
  1. 13 17
      Modules/Contents/UI/Source/PolyUITextInput.cpp

+ 13 - 17
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -927,24 +927,20 @@ String UITextInput::getSelectionText() {
 		return L"";
 		
 	String totalText = L"";
-	if(selectionTop == selectionBottom) {
-		totalText = lines[selectionTop].substr(selectionL, selectionR-selectionL);	
-		return totalText;
-	} else {
-		totalText += lines[selectionTop].substr(selectionL, lines[selectionTop].length()-selectionL);
-		totalText += L"\n";		
-	}
-	
-	if(selectionBottom > selectionTop+1) {
-		for(int i=selectionTop+1; i < selectionBottom; i++) {
-			totalText += lines[i];
-			if(i != selectionBottom-1)
-				totalText += L"\n";
-		}
+
+	// Set up iteration cursors
+	int currentLine = selectionTop;
+	int currentLeft = selectionL;
+
+	// Iterate over the inner lines(we'll be appending \n to these)
+	while(currentLine < selectionBottom) {
+		totalText += lines[currentLine].substr(currentLeft, lines[currentLine].length()-currentLeft) + '\n';
+		currentLine++;
+		currentLeft = 0;
 	}
-	
-	totalText += lines[selectionBottom].substr(0, selectionL);
-	
+	// Add the selection in the last line(no \n needed)
+	totalText += lines[currentLine].substr(currentLeft, selectionR-currentLeft);
+
 	return totalText;
 }