mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove selection made during search when nothing was found
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user