mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-65490
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package com.intellij.find;
|
||||
|
||||
import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
import com.intellij.codeInsight.highlighting.HighlightManagerImpl;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.find.impl.FindManagerImpl;
|
||||
import com.intellij.find.impl.LiveOccurrence;
|
||||
@@ -34,7 +32,6 @@ import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.editor.colors.EditorFontType;
|
||||
import com.intellij.openapi.editor.event.SelectionEvent;
|
||||
import com.intellij.openapi.editor.event.SelectionListener;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
@@ -73,6 +70,7 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class EditorSearchComponent extends JPanel implements DataProvider, LivePreview.CursorListener, SelectionListener {
|
||||
private static final int MATCHES_LIMIT = 100;
|
||||
private final JLabel myMatchInfoLabel;
|
||||
private final LinkLabel myClickToHighlightLabel;
|
||||
private final Project myProject;
|
||||
@@ -91,9 +89,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
private static final Color FOCUS_CATCHER_COLOR = new Color(0x9999ff);
|
||||
private final JComponent myToolbarComponent;
|
||||
private com.intellij.openapi.editor.event.DocumentAdapter myDocumentListener;
|
||||
private ArrayList<RangeHighlighter> myHighlighters = new ArrayList<RangeHighlighter>();
|
||||
|
||||
private int myMatchesLimit = 100;
|
||||
private final JCheckBox myCbRegexp;
|
||||
private final JCheckBox myCbWholeWords;
|
||||
private final JCheckBox myCbInComments;
|
||||
@@ -111,13 +107,31 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
return myEditor;
|
||||
}
|
||||
|
||||
public void notFound() {
|
||||
setNotFoundBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tooManyMatches() {
|
||||
myMatchInfoLabel.setText("More than " + myMatchesLimit + " matches");
|
||||
public void searchEndsWith(int count) {
|
||||
if (count <= getMatchesLimit()) {
|
||||
myClickToHighlightLabel.setVisible(false);
|
||||
|
||||
if (count > 0) {
|
||||
setRegularBackground();
|
||||
if (count > 1) {
|
||||
myMatchInfoLabel.setText(count + " matches");
|
||||
}
|
||||
else {
|
||||
myMatchInfoLabel.setText("1 match");
|
||||
}
|
||||
}
|
||||
else {
|
||||
setNotFoundBackground();
|
||||
myMatchInfoLabel.setText("No matches");
|
||||
}
|
||||
}
|
||||
else {
|
||||
setRegularBackground();
|
||||
myMatchInfoLabel.setText("More than 100 matches");
|
||||
myClickToHighlightLabel.setVisible(true);
|
||||
boldMatchInfo();
|
||||
}
|
||||
}
|
||||
};
|
||||
private final LivePreview myLivePreview;
|
||||
@@ -125,6 +139,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
|
||||
private boolean myIsReplace;
|
||||
private boolean myListeningSelection = false;
|
||||
private boolean myToChangeSelection = true;
|
||||
|
||||
@Nullable
|
||||
public Object getData(@NonNls final String dataId) {
|
||||
@@ -143,6 +158,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
|
||||
myIsReplace = isReplace;
|
||||
|
||||
setMatchesLimit(MATCHES_LIMIT);
|
||||
|
||||
GRADIENT_C1 = getBackground();
|
||||
GRADIENT_C2 = new Color(Math.max(0, GRADIENT_C1.getRed() - 0x18), Math.max(0, GRADIENT_C1.getGreen() - 0x18), Math.max(0, GRADIENT_C1.getBlue() - 0x18));
|
||||
@@ -270,7 +286,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
myClickToHighlightLabel = new LinkLabel("Click to highlight", null, new LinkListener() {
|
||||
@Override
|
||||
public void linkSelected(LinkLabel aSource, Object aLinkData) {
|
||||
myMatchesLimit = Integer.MAX_VALUE;
|
||||
setMatchesLimit(Integer.MAX_VALUE);
|
||||
updateResults(true);
|
||||
}
|
||||
});
|
||||
@@ -321,6 +337,10 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
|
||||
}
|
||||
|
||||
private void setMatchesLimit(int value) {
|
||||
myLivePreviewController.setMatchesLimit(value);
|
||||
}
|
||||
|
||||
private void configureReplacementPane() {
|
||||
JPanel replacement = createLeadPane();
|
||||
myReplaceField = createTextField();
|
||||
@@ -409,7 +429,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
|
||||
searchField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
protected void textChanged(final DocumentEvent e) {
|
||||
myMatchesLimit = 100;
|
||||
setMatchesLimit(MATCHES_LIMIT);
|
||||
updateResults(true);
|
||||
}
|
||||
});
|
||||
@@ -447,13 +467,13 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
}
|
||||
|
||||
private void searchBackward() {
|
||||
myLivePreview.prevOccurrence();
|
||||
moveCursor(false);
|
||||
|
||||
addCurrentTextToRecents();
|
||||
}
|
||||
|
||||
private void searchForward() {
|
||||
myLivePreview.nextOccurrence();
|
||||
moveCursor(true);
|
||||
|
||||
addCurrentTextToRecents();
|
||||
}
|
||||
@@ -467,7 +487,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
|
||||
@Override
|
||||
public void cursorMoved() {
|
||||
if (mySelectionOnly == null || !mySelectionOnly.isSelected()) {
|
||||
if (myToChangeSelection && (mySelectionOnly == null || !mySelectionOnly.isSelected())) {
|
||||
LiveOccurrence cursor = myLivePreview.getCursor();
|
||||
if (cursor != null) {
|
||||
TextRange range = cursor.getPrimaryRange();
|
||||
@@ -479,6 +499,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
myEditor.getCaretModel().moveToOffset(range.getStartOffset());
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
myToChangeSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,6 +509,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
}
|
||||
|
||||
public void moveCursor(boolean forwardOrBackward) {
|
||||
myToChangeSelection = true;
|
||||
if (forwardOrBackward) {
|
||||
myLivePreview.nextOccurrence();
|
||||
} else {
|
||||
@@ -512,13 +534,12 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
}
|
||||
|
||||
private void close() {
|
||||
removeCurrentHighlights();
|
||||
if (myEditor.getSelectionModel().hasSelection()) {
|
||||
myEditor.getCaretModel().moveToOffset(myEditor.getSelectionModel().getSelectionStart());
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
}
|
||||
IdeFocusManager.getInstance(myProject).requestFocus(myEditor.getContentComponent(), false);
|
||||
|
||||
myLivePreview.cleanUp();
|
||||
myEditor.setHeaderComponent(null);
|
||||
addCurrentTextToRecents();
|
||||
}
|
||||
@@ -554,7 +575,6 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
}
|
||||
|
||||
private void updateResults(final boolean allowedToChangedEditorSelection) {
|
||||
removeCurrentHighlights();
|
||||
myMatchInfoLabel.setFont(myMatchInfoLabel.getFont().deriveFont(Font.PLAIN));
|
||||
final String text = mySearchField.getText();
|
||||
if (text.length() == 0) {
|
||||
@@ -609,41 +629,10 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
model.setGlobal(!mySelectionOnly.isSelected());
|
||||
model.setPreserveCase(myPreserveCase.isEnabled() && myPreserveCase.isSelected());
|
||||
}
|
||||
|
||||
|
||||
myToChangeSelection = allowedToChangedEditorSelection;
|
||||
myLivePreviewController.setFindModel(model);
|
||||
myLivePreview.update();
|
||||
myLivePreview.setContinuation(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final int count = myLivePreview.getSearchResults().size();
|
||||
if (count <= myMatchesLimit) {
|
||||
myClickToHighlightLabel.setVisible(false);
|
||||
|
||||
if (count > 0) {
|
||||
setRegularBackground();
|
||||
if (count > 1) {
|
||||
myMatchInfoLabel.setText(count + " matches");
|
||||
}
|
||||
else {
|
||||
myMatchInfoLabel.setText("1 match");
|
||||
}
|
||||
}
|
||||
else {
|
||||
setNotFoundBackground();
|
||||
myMatchInfoLabel.setText("No matches");
|
||||
}
|
||||
}
|
||||
else {
|
||||
setRegularBackground();
|
||||
myMatchInfoLabel.setText("More than 100 matches");
|
||||
myClickToHighlightLabel.setVisible(true);
|
||||
boldMatchInfo();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,13 +678,6 @@ public class EditorSearchComponent extends JPanel implements DataProvider, LiveP
|
||||
updateResults(false);
|
||||
}
|
||||
|
||||
private void removeCurrentHighlights() {
|
||||
final HighlightManagerImpl highlightManager = (HighlightManagerImpl)HighlightManager.getInstance(myProject);
|
||||
for (RangeHighlighter highlighter : myHighlighters) {
|
||||
highlightManager.removeSegmentHighlighter(myEditor, highlighter);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextInField(final String text) {
|
||||
mySearchField.setText(text);
|
||||
updateResults(true);
|
||||
|
||||
@@ -24,4 +24,14 @@ public class LiveOccurrence {
|
||||
public void setSecondaryRanges(Collection<TextRange> secondaryRanges) {
|
||||
this.mySecondaryRanges = secondaryRanges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof LiveOccurrence) {
|
||||
if (myPrimaryRange.equals(((LiveOccurrence)o).getPrimaryRange())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,16 +384,9 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawMatch(Graphics2D g2d, Point start, Point end, int lineHeight, int horizontalGap, int verticalGap) {
|
||||
g2d.setColor(new Color(50, 50, 50));
|
||||
g2d.translate(0, start.y-verticalGap);
|
||||
UIUtil.drawSearchMatch(g2d, start.x-horizontalGap, end.x+horizontalGap, lineHeight+2*verticalGap);
|
||||
g2d.translate(0, -start.y+verticalGap);
|
||||
}
|
||||
|
||||
private void setCursor(LiveOccurrence liveOccurrence) {
|
||||
hideBalloon();
|
||||
boolean toNotify = myCursor != null && !myCursor.equals(liveOccurrence);
|
||||
boolean toNotify = myCursor == null || !myCursor.equals(liveOccurrence);
|
||||
|
||||
myCursor = liveOccurrence;
|
||||
|
||||
@@ -406,17 +399,7 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
highlightRange(myCursor.getPrimaryRange(), new TextAttributes(null, null, null, null, 0), dummy);
|
||||
if (!dummy.isEmpty()) {
|
||||
myCursorHighlighter = dummy.get(0);
|
||||
myCursorHighlighter.setCustomRenderer(new CustomHighlighterRenderer() {
|
||||
@Override
|
||||
public void paint(Editor editor, RangeHighlighter highlighter, Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
VisualPosition startVp = editor.offsetToVisualPosition(highlighter.getStartOffset());
|
||||
VisualPosition endVp = editor.offsetToVisualPosition(highlighter.getEndOffset());
|
||||
Point start = editor.visualPositionToXY(startVp);
|
||||
Point end = editor.visualPositionToXY(endVp);
|
||||
drawMatch(g2d, start, end, editor.getLineHeight(), 1, 4);
|
||||
}
|
||||
});
|
||||
myCursorHighlighter.setCustomRenderer(new MyCustomCursorRenderer());
|
||||
}
|
||||
|
||||
if (!insideVisibleArea(myEditor, myCursor.getPrimaryRange())) {
|
||||
@@ -434,7 +417,9 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
}
|
||||
if (toNotify) {
|
||||
for (CursorListener l : myListeners) {
|
||||
l.cursorMoved();
|
||||
if (l!= null) {
|
||||
l.cursorMoved();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,4 +506,21 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
|
||||
return visibleArea.contains(point);
|
||||
}
|
||||
|
||||
private static class MyCustomCursorRenderer implements CustomHighlighterRenderer {
|
||||
@Override
|
||||
public void paint(Editor editor, RangeHighlighter highlighter, Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
VisualPosition startVp = editor.offsetToVisualPosition(highlighter.getStartOffset());
|
||||
VisualPosition endVp = editor.offsetToVisualPosition(highlighter.getEndOffset());
|
||||
Point start = editor.visualPositionToXY(startVp);
|
||||
Point end = editor.visualPositionToXY(endVp);
|
||||
g2d.setColor(new Color(50, 50, 50));
|
||||
g2d.translate(0, start.y - 4);
|
||||
Color c1 = new Color(220, 200, 130);
|
||||
Color c2 = new Color(220, 170, 30);
|
||||
UIUtil.drawSearchMatch(g2d, start.x- 1, end.x+ 1, editor.getLineHeight() +2* 4, c1, c2);
|
||||
g2d.translate(0, -start.y + 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class LivePreviewControllerBase implements LivePreview.Delegate {
|
||||
}
|
||||
int offset = r.getStartOffset();
|
||||
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
|
||||
ArrayList<FindResult> results = new ArrayList<FindResult>();
|
||||
final ArrayList<FindResult> results = new ArrayList<FindResult>();
|
||||
|
||||
while (true) {
|
||||
FindManager findManager = FindManager.getInstance(editor.getProject());
|
||||
@@ -77,28 +77,24 @@ public class LivePreviewControllerBase implements LivePreview.Delegate {
|
||||
if (results.size() > myMatchesLimit) break;
|
||||
}
|
||||
if (results.size() < myMatchesLimit) {
|
||||
if (results.isEmpty()) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
notFound();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
findResultsToOccurrences(results, occurrences);
|
||||
} else {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tooManyMatches();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
searchEndsWith(results.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
return occurrences;
|
||||
}
|
||||
|
||||
protected void tooManyMatches() { }
|
||||
protected void searchEndsWith(int size) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getReplacementPreviewText(Editor editor, LiveOccurrence liveOccurrence) {
|
||||
@@ -148,8 +144,7 @@ public class LivePreviewControllerBase implements LivePreview.Delegate {
|
||||
|
||||
@Override
|
||||
public Editor getEditor(Ref<Boolean> needToUpdate) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
public void notFound() {}
|
||||
}
|
||||
|
||||
@@ -761,9 +761,15 @@ public class UIUtil {
|
||||
final int startX,
|
||||
final int endX,
|
||||
final int height) {
|
||||
Color c1 = new Color(255, 234, 162);
|
||||
Color c2 = new Color(255, 208, 66);
|
||||
drawSearchMatch(g, startX, endX, height, c1, c2);
|
||||
}
|
||||
|
||||
public static void drawSearchMatch(Graphics2D g, int startX, int endX, int height, Color c1, Color c2) {
|
||||
final boolean drawRound = endX - startX > 4;
|
||||
|
||||
g.setPaint(new GradientPaint(startX, 2, new Color(255, 234, 162), startX, height - 5, new Color(255, 208, 66)));
|
||||
g.setPaint(new GradientPaint(startX, 2, c1, startX, height - 5, c2));
|
||||
g.fillRect(startX, 3, endX - startX, height - 5);
|
||||
|
||||
if (drawRound) {
|
||||
|
||||
Reference in New Issue
Block a user