remove selection made during search when nothing was found

This commit is contained in:
Maxim.Mossienko
2016-09-13 15:18:31 +02:00
parent ca2bafc98e
commit f2eccfa6c5
3 changed files with 7 additions and 1 deletions
@@ -60,6 +60,8 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
initFind();
myFindModel.setStringToFind("a");
checkResults();
myFindModel.setStringToFind("a2");
assertTrue(!myEditor.getSelectionModel().hasSelection());
}
public void testEmacsLikeFallback() throws Exception {
@@ -91,12 +91,13 @@ public class SearchResults implements DocumentListener {
private final Stack<Pair<FindModel, FindResult>> myCursorPositions = new Stack<>();
private final SelectionManager mySelectionManager = new SelectionManager(this);
private final SelectionManager mySelectionManager;
public SearchResults(Editor editor, Project project) {
myEditor = editor;
myProject = project;
myEditor.getDocument().addDocumentListener(this);
mySelectionManager = new SelectionManager(this); // important to initialize last for accessing other fields
}
public void setNotFoundState(boolean isForward) {
@@ -26,10 +26,12 @@ import java.util.List;
public class SelectionManager {
@NotNull private final SearchResults mySearchResults;
private final boolean myHadSelectionInitially;
private final List<FoldRegion> myRegionsToRestore = new ArrayList<>();
public SelectionManager(@NotNull SearchResults results) {
mySearchResults = results;
myHadSelectionInitially = results.getEditor().getSelectionModel().hasSelection();
}
public void updateSelection(boolean removePreviousSelection, boolean removeAllPreviousSelections) {
@@ -39,6 +41,7 @@ public class SelectionManager {
}
final FindResult cursor = mySearchResults.getCursor();
if (cursor == null) {
if (removePreviousSelection && !myHadSelectionInitially) editor.getSelectionModel().removeSelection();
return;
}
if (mySearchResults.getFindModel().isGlobal()) {