Browse Source

Visual tests suite: Keep scroll position when reloading test

Michael Ragazzon 3 years ago
parent
commit
0a6f6c4c4a

+ 4 - 3
Tests/Source/VisualTests/TestNavigator.cpp

@@ -189,7 +189,7 @@ void TestNavigator::ProcessEvent(Rml::Event& event)
 		}
 		else if (key_identifier == Rml::Input::KI_R && key_ctrl)
 		{
-			LoadActiveTest();
+			LoadActiveTest(true);
 		}
 		else if (key_identifier == Rml::Input::KI_S && key_ctrl)
 		{
@@ -353,10 +353,11 @@ void TestNavigator::ProcessEvent(Rml::Event& event)
 	}
 }
 
-void TestNavigator::LoadActiveTest()
+void TestNavigator::LoadActiveTest(bool keep_scroll_position)
 {
 	const TestSuite& suite = CurrentSuite();
-	viewer->LoadTest(suite.GetDirectory(), suite.GetFilename(), suite.GetIndex(), suite.GetNumTests(), suite.GetFilterIndex(), suite.GetNumFilteredTests(), suite_index, (int)test_suites.size());
+	viewer->LoadTest(suite.GetDirectory(), suite.GetFilename(), suite.GetIndex(), suite.GetNumTests(), suite.GetFilterIndex(),
+		suite.GetNumFilteredTests(), suite_index, (int)test_suites.size(), keep_scroll_position);
 	viewer->ShowSource(source_state);
 	ShowReference(false, true);
 	UpdateGoToText();

+ 1 - 1
Tests/Source/VisualTests/TestNavigator.h

@@ -53,7 +53,7 @@ private:
 
 	TestSuite& CurrentSuite() { return test_suites[suite_index]; }
 
-	void LoadActiveTest();
+	void LoadActiveTest(bool keep_scroll_position = false);
 
 	ComparisonResult CompareCurrentView();
 

+ 6 - 1
Tests/Source/VisualTests/TestViewer.cpp

@@ -191,10 +191,13 @@ bool TestViewer::IsHelpVisible() const
 
 
 
-bool TestViewer::LoadTest(const Rml::String& directory, const Rml::String& filename, int test_index, int number_of_tests, int filtered_test_index, int filtered_number_of_tests, int suite_index, int number_of_suites)
+bool TestViewer::LoadTest(const Rml::String& directory, const Rml::String& filename, int test_index, int number_of_tests, int filtered_test_index,
+	int filtered_number_of_tests, int suite_index, int number_of_suites, bool keep_scroll_position)
 {
+	float scroll_position = 0.f;
 	if (document_test)
 	{
+		scroll_position = document_test->GetScrollTop();
 		document_test->Close();
 		document_test = nullptr;
 	}
@@ -225,6 +228,8 @@ bool TestViewer::LoadTest(const Rml::String& directory, const Rml::String& filen
 			return false;
 
 		document_test->Show(ModalFlag::None, FocusFlag::None);
+		if (keep_scroll_position)
+			document_test->SetScrollTop(scroll_position);
 
 		for (const LinkItem& item : link_handler->GetLinkList())
 		{

+ 2 - 1
Tests/Source/VisualTests/TestViewer.h

@@ -47,7 +47,8 @@ public:
 	void ShowHelp(bool show);
 	bool IsHelpVisible() const;
 
-	bool LoadTest(const Rml::String& directory, const Rml::String& filename, int test_index, int number_of_tests, int filtered_test_index, int filtered_number_of_tests, int suite_index, int number_of_suites);
+	bool LoadTest(const Rml::String& directory, const Rml::String& filename, int test_index, int number_of_tests, int filtered_test_index,
+		int filtered_number_of_tests, int suite_index, int number_of_suites, bool keep_scroll_position = false);
 
 	void SetGoToText(const Rml::String& rml);