فهرست منبع

Merge pull request #193 from CIB/undo_words

You can now undo typed words in TextInput
Ivan Safrin 13 سال پیش
والد
کامیت
eb3a434c9f
2فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 1 0
      Modules/Contents/UI/Include/PolyUITextInput.h
  2. 9 0
      Modules/Contents/UI/Source/PolyUITextInput.cpp

+ 1 - 0
Modules/Contents/UI/Include/PolyUITextInput.h

@@ -231,6 +231,7 @@ namespace Polycode {
 			UITextInputUndoState undoStates[MAX_TEXTINPUT_UNDO_STATES];
 			UITextInputUndoState undoStates[MAX_TEXTINPUT_UNDO_STATES];
 			int undoStateIndex;
 			int undoStateIndex;
 			int maxRedoIndex;
 			int maxRedoIndex;
+			bool isTypingWord;
 		
 		
 			bool multiLine;
 			bool multiLine;
 			Timer *blinkTimer;
 			Timer *blinkTimer;

+ 9 - 0
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -52,6 +52,8 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
 	settingText = false;	
 	settingText = false;	
 	
 	
 	needFullRedraw = false;
 	needFullRedraw = false;
+
+	isTypingWord = false;
 	
 	
 	numLines = 0;
 	numLines = 0;
 	
 	
@@ -998,6 +1000,10 @@ void UITextInput::saveUndoState() {
 	}
 	}
 	
 	
 	maxRedoIndex = undoStateIndex;
 	maxRedoIndex = undoStateIndex;
+	// By default, reset the isTypingWord status.
+	// If we are typing a word after all, the caller
+	// will immediately reset it to 1.
+	isTypingWord = 0;
 }
 }
 
 
 void UITextInput::setUndoState(UITextInputUndoState state) {
 void UITextInput::setUndoState(UITextInputUndoState state) {
@@ -1255,6 +1261,9 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 		if(!isNumberOnly || (isNumberOnly && ((charCode > 47 && charCode < 58) || (charCode == '.' || charCode == '-')))) {
 		if(!isNumberOnly || (isNumberOnly && ((charCode > 47 && charCode < 58) || (charCode == '.' || charCode == '-')))) {
 			if(!isNumberOrCharacter(charCode)) { 
 			if(!isNumberOrCharacter(charCode)) { 
 				saveUndoState();
 				saveUndoState();
+			} else if (!isTypingWord) {
+				saveUndoState();
+				isTypingWord = 1;
 			}
 			}
 			if(hasSelection)
 			if(hasSelection)
 				deleteSelection();
 				deleteSelection();