Pārlūkot izejas kodu

UITextInput will only scroll to reveal current line (when typing or in undo/redo operations) only if it's off screen

Ivan Safrin 12 gadi atpakaļ
vecāks
revīzija
d238b1acac

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

@@ -368,6 +368,8 @@ namespace Polycode {
 		
 			static UIGlobalMenu *globalMenuSingleton;
 		
+			void showCurrentLineIfOffscreen();
+		
 			void readjustBuffer(int lineStart=0, int lineEnd=-1);
 			void updateWordWrap(int lineStart, int lineEnd);
 			

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

@@ -1568,7 +1568,21 @@ void UITextInput::setUndoState(UITextInputUndoState state) {
 	restructLines();		
 	readjustBuffer();
 
-	showLine(state.lineOffset, false);	
+	showCurrentLineIfOffscreen();
+}
+
+void UITextInput::showCurrentLineIfOffscreen() {
+	if(!multiLine)
+		return;
+		
+	int bufferOffset = -linesContainer->position.y/ ( lineHeight+lineSpacing);	
+	int heightInLines = (height / ( lineHeight+lineSpacing)) + 1;
+			
+	if(lines[actualLineOffset].wordWrapLineIndex > bufferOffset && lines[actualLineOffset].wordWrapLineIndex < bufferOffset + heightInLines) {
+	
+	} else {
+		showLine(actualLineOffset, false);	
+	}
 }
 
 void UITextInput::Undo() {
@@ -1990,6 +2004,8 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
 			ctext += charCode + text2;
 			actualCaretPosition++;
 			_changedText = true;
+			
+			showCurrentLineIfOffscreen();
 		}
 	}