Browse Source

Move caret properly when adding/removing a line due to word wrap

Marko Pintera 12 years ago
parent
commit
c898475a4a
3 changed files with 17 additions and 5 deletions
  1. 16 3
      BansheeEngine/Source/BsGUIInputBox.cpp
  2. 1 1
      BansheeEngine/Source/BsGUIInputCaret.cpp
  3. 0 1
      TODO.txt

+ 16 - 3
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -392,7 +392,11 @@ namespace BansheeEngine
 							mText.erase(charIdx, 1);
 							mText.erase(charIdx, 1);
 							mInputCaret->updateText(getTextDesc());
 							mInputCaret->updateText(getTextDesc());
 
 
-							mInputCaret->moveCaretLeft();
+							if(charIdx > 0)
+								charIdx--;
+
+							mInputCaret->moveCaretToChar(charIdx, CARET_AFTER);
+
 							scrollTextToCaret();
 							scrollTextToCaret();
 						}
 						}
 					}
 					}
@@ -432,6 +436,13 @@ namespace BansheeEngine
 						{
 						{
 							mText.erase(charIdx, 1);
 							mText.erase(charIdx, 1);
 							mInputCaret->updateText(getTextDesc());
 							mInputCaret->updateText(getTextDesc());
+
+							if(charIdx > 0)
+								charIdx--;
+
+							mInputCaret->moveCaretToChar(charIdx, CARET_AFTER);
+
+							scrollTextToCaret();
 						}
 						}
 					}
 					}
 
 
@@ -617,10 +628,12 @@ namespace BansheeEngine
 				clearSelection();
 				clearSelection();
 			}
 			}
 
 
-			mText.insert(mText.begin() + mInputCaret->getCharIdxAtCaretPos(), ev.getInputChar());
+			UINT32 charIdx = mInputCaret->getCharIdxAtCaretPos();
+			mText.insert(mText.begin() + charIdx, ev.getInputChar());
 			mInputCaret->updateText(getTextDesc());
 			mInputCaret->updateText(getTextDesc());
 
 
-			mInputCaret->moveCaretRight();
+			mInputCaret->moveCaretToChar(charIdx, CARET_AFTER);
+
 			scrollTextToCaret();
 			scrollTextToCaret();
 
 
 			markAsDirty();
 			markAsDirty();

+ 1 - 1
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -166,7 +166,7 @@ namespace BansheeEngine
 
 
 			UINT32 numChars = lineDesc.getEndChar() - lineDesc.getStartChar();
 			UINT32 numChars = lineDesc.getEndChar() - lineDesc.getStartChar();
 			UINT32 numCaretPositions = lineDesc.getEndChar(false) - lineDesc.getStartChar();
 			UINT32 numCaretPositions = lineDesc.getEndChar(false) - lineDesc.getStartChar();
-			if(charIdx > (curCharIdx + numChars))
+			if(charIdx >= (curCharIdx + numChars))
 			{
 			{
 				curCharIdx += numChars;
 				curCharIdx += numChars;
 				curPos += numCaretPositions;
 				curPos += numCaretPositions;

+ 0 - 1
TODO.txt

@@ -24,7 +24,6 @@ IMMEDIATE:
 
 
 TextBox needed elements:
 TextBox needed elements:
  - Clicking on text seems to return slightly offset caret location
  - Clicking on text seems to return slightly offset caret location
- - Moving to the new line due to word wrap should move the caret twice (same as going backwards when deleting most likely)
  - Key-repeat? Pressing left/right/up/down arrows doesn't repeat the keys (also delete/backspace)
  - Key-repeat? Pressing left/right/up/down arrows doesn't repeat the keys (also delete/backspace)
  - Drag mouse to update selection
  - Drag mouse to update selection
  - Get DebugCamera to ignore input if GUI has already processed it
  - Get DebugCamera to ignore input if GUI has already processed it