mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-63384
This commit is contained in:
@@ -22,6 +22,9 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* Represents the settings of a Find, Replace, Find in Path or Replace in Path
|
||||
* operations.
|
||||
@@ -132,6 +135,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
|
||||
public void setStringToFind(@NotNull String s) {
|
||||
LOG.assertTrue(s.length() > 0);
|
||||
myStringToFind = s;
|
||||
myPattern = NO_PATTERN;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -618,4 +622,24 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
|
||||
public void setInCommentsOnly(boolean inCommentsOnly) {
|
||||
isInCommentsOnly = inCommentsOnly;
|
||||
}
|
||||
|
||||
private static final Pattern NO_PATTERN = Pattern.compile("");
|
||||
private Pattern myPattern = NO_PATTERN;
|
||||
public Pattern compileRegExp() {
|
||||
String toFind = getStringToFind();
|
||||
|
||||
Pattern pattern = myPattern;
|
||||
if (pattern == NO_PATTERN) {
|
||||
try {
|
||||
myPattern = pattern = Pattern.compile(toFind, isCaseSensitive() ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
catch(PatternSyntaxException e){
|
||||
LOG.error(e);
|
||||
myPattern = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
@@ -146,8 +146,8 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
|
||||
DefaultActionGroup group = new DefaultActionGroup("search bar", false);
|
||||
group.add(new ShowHistoryAction());
|
||||
group.add(new PrevOccurenceAction());
|
||||
group.add(new NextOccurenceAction());
|
||||
group.add(new PrevOccurrenceAction());
|
||||
group.add(new NextOccurrenceAction());
|
||||
group.add(new FindAllAction());
|
||||
|
||||
final ActionToolbar tb = ActionManager.getInstance().createActionToolbar("SearchBar", group, true);
|
||||
@@ -250,7 +250,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
setSmallerFontAndOpaque(myClickToHighlightLabel);
|
||||
myClickToHighlightLabel.setVisible(false);
|
||||
|
||||
JLabel closeLabel = new JLabel(" ", IconLoader.getIcon("/actions/cross.png"), JLabel.RIGHT);
|
||||
JLabel closeLabel = new JLabel(" ", IconLoader.getIcon("/actions/cross.png"), SwingConstants.RIGHT);
|
||||
closeLabel.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
close();
|
||||
@@ -297,7 +297,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
addCurrentTextToRecents();
|
||||
}
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, SystemInfo.isMac ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK), JComponent.WHEN_FOCUSED);
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, SystemInfo.isMac ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_FOCUSED);
|
||||
|
||||
final String initialText = myEditor.getSelectionModel().getSelectedText();
|
||||
|
||||
@@ -459,7 +459,9 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
while (true) {
|
||||
FindResult result = findManager.findString(myEditor.getDocument().getCharsSequence(), offset, model, virtualFile);
|
||||
if (!result.isStringFound()) break;
|
||||
offset = result.getEndOffset();
|
||||
int newOffset = result.getEndOffset();
|
||||
if (offset == newOffset) break;
|
||||
offset = newOffset;
|
||||
results.add(result);
|
||||
|
||||
if (results.size() > myMatchesLimit) break;
|
||||
@@ -597,16 +599,15 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
updateResults(true);
|
||||
}
|
||||
|
||||
private class PrevOccurenceAction extends AnAction implements DumbAware {
|
||||
public PrevOccurenceAction() {
|
||||
private class PrevOccurrenceAction extends AnAction implements DumbAware {
|
||||
public PrevOccurrenceAction() {
|
||||
copyFrom(ActionManager.getInstance().getAction(IdeActions.ACTION_PREVIOUS_OCCURENCE));
|
||||
|
||||
ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
|
||||
ContainerUtil
|
||||
.addAll(shortcuts, ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS).getShortcutSet().getShortcuts());
|
||||
ContainerUtil
|
||||
.addAll(shortcuts, ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP).getShortcutSet().getShortcuts());
|
||||
shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK), null));
|
||||
ContainerUtil.addAll(shortcuts,ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS).getShortcutSet().getShortcuts());
|
||||
ContainerUtil.addAll(shortcuts,
|
||||
ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP).getShortcutSet().getShortcuts());
|
||||
shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), null));
|
||||
|
||||
registerCustomShortcutSet(
|
||||
new CustomShortcutSet(shortcuts.toArray(new Shortcut[shortcuts.size()])),
|
||||
@@ -626,8 +627,8 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
return myOkToSearch && myHasMatches;
|
||||
}
|
||||
|
||||
private class NextOccurenceAction extends AnAction implements DumbAware {
|
||||
public NextOccurenceAction() {
|
||||
private class NextOccurrenceAction extends AnAction implements DumbAware {
|
||||
public NextOccurrenceAction() {
|
||||
copyFrom(ActionManager.getInstance().getAction(IdeActions.ACTION_NEXT_OCCURENCE));
|
||||
ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
|
||||
ContainerUtil.addAll(shortcuts, ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT).getShortcutSet().getShortcuts());
|
||||
@@ -657,7 +658,7 @@ public class EditorSearchComponent extends JPanel implements DataProvider {
|
||||
|
||||
ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
|
||||
ContainerUtil.addAll(shortcuts, ActionManager.getInstance().getAction(IdeActions.ACTION_FIND).getShortcutSet().getShortcuts());
|
||||
shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_DOWN_MASK), null));
|
||||
shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK), null));
|
||||
ContainerUtil.addAll(shortcuts, ActionManager.getInstance().getAction("IncrementalSearch").getShortcutSet().getShortcuts());
|
||||
|
||||
registerCustomShortcutSet(
|
||||
|
||||
@@ -508,18 +508,8 @@ public class FindManagerImpl extends FindManager implements PersistentStateCompo
|
||||
}
|
||||
|
||||
private static Matcher compileRegExp(FindModel model, CharSequence text) {
|
||||
String toFind = model.getStringToFind();
|
||||
|
||||
Pattern pattern;
|
||||
try {
|
||||
pattern = Pattern.compile(toFind, model.isCaseSensitive() ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
catch(PatternSyntaxException e){
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return pattern.matcher(text);
|
||||
Pattern pattern = model.compileRegExp();
|
||||
return pattern == null ? null : pattern.matcher(text);
|
||||
}
|
||||
|
||||
public String getStringToReplace(@NotNull String foundString, @NotNull FindModel model) {
|
||||
|
||||
Reference in New Issue
Block a user