@@ -833,6 +833,77 @@ public void testResetIncrementalBaseLocation() {
833833 findReplaceLogic .resetIncrementalBaseLocation ();
834834 findReplaceLogic .performSearch ();
835835 assertThat (textViewer .getSelectedRange (), is (new Point (5 , 4 )));
836+
837+ textViewer .setSelectedRange (7 , 0 );
838+ findReplaceLogic .resetIncrementalBaseLocation ();
839+ findReplaceLogic .performSearch ();
840+ assertThat (textViewer .getSelectedRange (), is (new Point (10 , 4 )));
841+
842+ textViewer .setSelectedRange (10 , 0 );
843+ findReplaceLogic .resetIncrementalBaseLocation ();
844+ findReplaceLogic .performSearch ();
845+ assertThat (textViewer .getSelectedRange (), is (new Point (10 , 4 )));
846+ assertThat (((FindReplaceLogic ) findReplaceLogic ).getRestoreBaseLocation (), is (new Point (10 , 0 )));
847+ }
848+
849+ @ Test
850+ public void testRestoreBaseLocationCapturedOnNewSearch () {
851+ String setupString = "alpha beta gamma" ;
852+ TextViewer textViewer = setupTextViewer (setupString );
853+ textViewer .setSelectedRange (6 , 0 ); // caret after 'alpha '
854+ IFindReplaceLogic logic = setupFindReplaceLogicObject (textViewer );
855+ logic .activate (SearchOptions .FORWARD );
856+ logic .activate (SearchOptions .INCREMENTAL );
857+
858+ // Initially empty find string
859+ logic .setFindString ("" );
860+ // Now start a new search (transition empty -> non-empty)
861+ logic .setFindString ("beta" );
862+ // Expect the stored restore location to match the caret before search started
863+ assertThat (((FindReplaceLogic ) logic ).getRestoreBaseLocation (), is (new Point (6 , 0 )));
864+ }
865+
866+ @ Test
867+ public void testCaretRestoredWhenSearchCleared () {
868+ String setupString = "alpha beta gamma" ;
869+ TextViewer textViewer = setupTextViewer (setupString );
870+ textViewer .setSelectedRange (0 , 0 );
871+ IFindReplaceLogic logic = setupFindReplaceLogicObject (textViewer );
872+ logic .activate (SearchOptions .FORWARD );
873+ logic .activate (SearchOptions .INCREMENTAL );
874+
875+ logic .setFindString ("beta" );
876+ assertThat (textViewer .getSelectedRange (), is (new Point (6 , 4 ))); // found "beta"
877+
878+ // Clear the search field - should restore caret
879+ logic .setFindString ("" );
880+ logic .performSearch ();
881+ // Expect caret restored to starting location (0,0)
882+ assertThat (textViewer .getSelectedRange (), is (new Point (0 , 0 )));
883+ }
884+
885+ @ Test
886+ public void testRestoreBaseLocationRefreshedBetweenSessions () {
887+ String setupString = "alpha beta gamma" ;
888+ TextViewer textViewer = setupTextViewer (setupString );
889+ IFindReplaceLogic logic = setupFindReplaceLogicObject (textViewer );
890+ logic .activate (SearchOptions .FORWARD );
891+ logic .activate (SearchOptions .INCREMENTAL );
892+
893+ // First search session
894+ textViewer .setSelectedRange (0 , 0 );
895+ logic .setFindString ("alpha" );
896+ assertThat (((FindReplaceLogic ) logic ).getRestoreBaseLocation (), is (new Point (0 , 0 )));
897+
898+ // Clear the search (simulate reopen of overlay)
899+ logic .setFindString ("" );
900+ logic .performSearch ();
901+
902+ // Move caret and start new search session
903+ textViewer .setSelectedRange (6 , 0 );
904+ logic .setFindString ("beta" );
905+ // Verify that restoreBaseLocation updated to the new caret position
906+ assertThat (((FindReplaceLogic ) logic ).getRestoreBaseLocation (), is (new Point (6 , 0 )));
836907 }
837908
838909 @ Test
0 commit comments