Преглед изворни кода

Merge pull request #188 from CIB/cleanup

More cleanup and bugfixes
Ivan Safrin пре 13 година
родитељ
комит
9779eb9aef
2 измењених фајлова са 17 додато и 17 уклоњено
  1. 4 0
      IDE/Contents/Source/PolycodeEditor.cpp
  2. 13 17
      Modules/Contents/UI/Source/PolyUITextInput.cpp

+ 4 - 0
IDE/Contents/Source/PolycodeEditor.cpp

@@ -66,6 +66,10 @@ void PolycodeEditor::setHasChanges(bool newVal) {
 void PolycodeEditor::handleEvent(Event *event) {
 	if(event->getDispatcher() == CoreServices::getInstance()->getCore()) {
 		switch(event->getEventCode()) {
+
+			// Only copypaste of more complex IDE entities is handled here.
+			// Pure text copy/paste is handled in:
+			// Modules/Contents/UI/Source/PolyUITextInput.cpp
 			case Core::EVENT_COPY:
 			{
 				void *data = NULL;

+ 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;
 }