Browse Source

Fixed bug in Textbox that added text when unable to delete anything.

David Piuva 2 years ago
parent
commit
fb8b5e230c
1 changed files with 22 additions and 8 deletions
  1. 22 8
      Source/DFPSR/gui/components/TextBox.cpp

+ 22 - 8
Source/DFPSR/gui/components/TextBox.cpp

@@ -443,14 +443,28 @@ void TextBox::receiveKeyboardEvent(const KeyboardEvent& event) {
 			if (selected && (event.dsrKey == DsrKey_BackSpace || event.dsrKey == DsrKey_Delete)) {
 			if (selected && (event.dsrKey == DsrKey_BackSpace || event.dsrKey == DsrKey_Delete)) {
 				// Remove selection
 				// Remove selection
 				this->replaceSelection(U"");
 				this->replaceSelection(U"");
-			} else if (event.dsrKey == DsrKey_BackSpace && canGoLeft) {
-				// Erase left of beam
-				this->beamLocation--;
-				this->replaceSelection(U"");
-			} else if (event.dsrKey == DsrKey_Delete && canGoRight) {
-				// Erase right of beam
-				this->beamLocation++;
-				this->replaceSelection(U"");
+			} else if (event.dsrKey == DsrKey_BackSpace) {
+				if (this->selectionStart == this->beamLocation) {
+					if (this->beamLocation > 0) {
+						// Erase left of beam
+						this->beamLocation--;
+						this->replaceSelection(U"");
+					}
+				} else {
+					// Erase selection
+					this->replaceSelection(U"");
+				}
+			} else if (event.dsrKey == DsrKey_Delete) {
+				if (this->selectionStart == this->beamLocation) {
+					if (this->beamLocation < textLength) {
+						// Erase right of beam
+						this->beamLocation++;
+						this->replaceSelection(U"");
+					}
+				} else {
+					// Erase selection
+					this->replaceSelection(U"");
+				}
 			} else if (event.dsrKey == DsrKey_Home) {
 			} else if (event.dsrKey == DsrKey_Home) {
 				// Move to the line start using Home
 				// Move to the line start using Home
 				this->placeBeamAtCharacter(getLineStart(this->text.value, this->beamLocation), removeSelection);
 				this->placeBeamAtCharacter(getLineStart(this->text.value, this->beamLocation), removeSelection);