private void updateResults(final boolean allowedToChangedEditorSelection) { final String text = myFindModel.getStringToFind(); if (text.length() == 0) { nothingToSearchFor(); } else { if (myFindModel.isRegularExpressions()) { try { Pattern.compile(text); } catch (Exception e) { setNotFoundBackground(); myClickToHighlightLabel.setVisible(false); mySearchResults.clear(); myMatchInfoLabel.setText("Incorrect regular expression"); return; } } final FindManager findManager = FindManager.getInstance(myProject); if (allowedToChangedEditorSelection) { findManager.setFindWasPerformed(); FindModel copy = new FindModel(); copy.copyFrom(myFindModel); copy.setReplaceState(false); findManager.setFindNextModel(copy); } if (myLivePreviewController != null) { myLivePreviewController.updateInBackground(myFindModel, allowedToChangedEditorSelection); } } }
private void updateSearchComponent() { final int oldCaretPosition = mySearchTextComponent != null ? mySearchTextComponent.getCaretPosition() : 0; String oldText = mySearchTextComponent != null ? mySearchTextComponent.getText() : myFindModel.getStringToFind(); if (!updateTextComponent(true)) { return; } if (oldText != null) { mySearchTextComponent.setText(oldText); } mySearchTextComponent .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { searchFieldDocumentChanged(); } }); } }); } }); mySearchTextComponent.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (StringUtil.isEmpty(mySearchTextComponent.getText())) { close(); } else { requestFocus(myEditor.getContentComponent()); addTextToRecent(EditorSearchComponent.this.mySearchTextComponent); } } }, KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, SystemInfo.isMac ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_FOCUSED); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { mySearchTextComponent.setCaretPosition(oldCaretPosition); } }); new RestorePreviousSettingsAction(this, mySearchTextComponent); new VariantsCompletionAction( mySearchTextComponent); // It registers a shortcut set automatically on construction }