mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
search and replace: navigation through occurrences
This commit is contained in:
@@ -166,8 +166,6 @@ public class EditorSearchComponent extends JPanel implements DataProvider, Selec
|
||||
myEditor.getCaretModel().moveToOffset(range.getEndOffset());
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
|
||||
myEditor.getCaretModel().moveToOffset(range.getStartOffset());
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
myToChangeSelection = false;
|
||||
}
|
||||
@@ -528,6 +526,13 @@ public class EditorSearchComponent extends JPanel implements DataProvider, Selec
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceCurrent() {
|
||||
if (mySearchResults.getCursor() != null) {
|
||||
String replacement = myLivePreviewController.getReplacementPreviewText(myEditor, mySearchResults.getCursor());
|
||||
myLivePreviewController.performReplace(mySearchResults.getCursor(), replacement, myEditor);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setSmallerFontAndOpaque(final JComponent component) {
|
||||
setSmallerFont(component);
|
||||
component.setOpaque(false);
|
||||
|
||||
@@ -237,6 +237,17 @@ public class SearchResults {
|
||||
return firstVisibleOccurrence != null ? firstVisibleOccurrence : firstOccurrence;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LiveOccurrence firstOccurrenceBeforeCaret() {
|
||||
int offset = getEditor().getCaretModel().getOffset();
|
||||
for (int i = getOccurrences().size()-1; i >= 0; --i) {
|
||||
if (getOccurrences().get(i).getPrimaryRange().getEndOffset() < offset) {
|
||||
return getOccurrences().get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LiveOccurrence firstOccurrenceAfterCaret() {
|
||||
LiveOccurrence afterCaret = null;
|
||||
@@ -294,7 +305,7 @@ public class SearchResults {
|
||||
}
|
||||
|
||||
public void prevOccurrence() {
|
||||
LiveOccurrence prev = prevOccurrence(myCursor);
|
||||
LiveOccurrence prev = firstOccurrenceBeforeCaret();
|
||||
if (prev == null && !getOccurrences().isEmpty()) {
|
||||
prev = getOccurrences().get(getOccurrences().size() - 1);
|
||||
}
|
||||
@@ -302,7 +313,7 @@ public class SearchResults {
|
||||
}
|
||||
|
||||
public void nextOccurrence() {
|
||||
LiveOccurrence next = nextOccurrence(myCursor);
|
||||
LiveOccurrence next = firstOccurrenceAfterCaret();
|
||||
if (next == null && !getOccurrences().isEmpty()) {
|
||||
next = getOccurrences().get(0);
|
||||
}
|
||||
|
||||
+6
-2
@@ -42,8 +42,12 @@ public class IncrementalFindAction extends EditorAction {
|
||||
if (!editor.isOneLineMode()) {
|
||||
final JComponent headerComponent = editor.getHeaderComponent();
|
||||
if (headerComponent instanceof EditorSearchComponent) {
|
||||
((EditorSearchComponent) headerComponent).setInitialText(editor.getSelectionModel().getSelectedText());
|
||||
headerComponent.requestFocus();
|
||||
if (myReplace) {
|
||||
((EditorSearchComponent)headerComponent).replaceCurrent();
|
||||
} else {
|
||||
((EditorSearchComponent) headerComponent).setInitialText(editor.getSelectionModel().getSelectedText());
|
||||
headerComponent.requestFocus();
|
||||
}
|
||||
}
|
||||
else {
|
||||
final EditorSearchComponent header = new EditorSearchComponent(editor, project, myReplace);
|
||||
|
||||
Reference in New Issue
Block a user