boolean () { if (!myToggleRegularExpression.isSelected()) return false; String stringToFind = mySearchReplaceComponent.getSearchTextComponent().getText(); // "pageSize / 10", because it's strictly shorter then even full page consisted of only 4-byte symbols and much longer then simple stringsToFind return stringToFind.length() > largeFileEditor.getPageSize() / 10 || stringToFind.contains("*") || stringToFind.contains("+") || stringToFind.contains("{"); } private void createActions() { myNextOccurrenceAction = new LargeFilePrevNextOccurrenceAction(this, true); myPrevOccurrenceAction = new LargeFilePrevNextOccurrenceAction(this, false); myFindAllAction = new LargeFileFindAllAction(this); myFindForwardAction = new FindForwardBackwardAction(true, this); myFindBackwardAction = new FindForwardBackwardAction(false, this); myToggleCaseSensitiveAction = new LargeFileToggleAction(this, EditorBundle.message("large.file.editor.match.case.action.mnemonic.text")); myToggleWholeWordsAction = new LargeFileToggleAction(this, EditorBundle.message("large.file.editor.words.action.mnemonic.text")) { @Override public void update(@NotNull AnActionEvent e) { boolean enabled = myToggleRegularExpression != null && !myToggleRegularExpression.isSelected(e); boolean visible = mySearchReplaceComponent == null || !mySearchReplaceComponent.isMultiline(); e.getPresentation().setEnabled(enabled); e.getPresentation().setVisible(visible); setSelected(e, isSelected(e) && enabled && visible); super.update(e); } @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return super.getActionUpdateThread(); } }; myToggleRegularExpression = new LargeFileToggleAction(this, EditorBundle.message("large.file.editor.regex.action.mnemonic.text")) { @Override public void setSelected(boolean state) { super.setSelected(state); if (state && myToggleWholeWordsAction != null) { myToggleWholeWordsAction.setSelected(false); } } @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return super.getActionUpdateThread(); } }; myStatusTextAction = new LargeFileStatusTextAction(this); } private void createSearchReplaceComponent() { mySearchReplaceComponent = SearchReplaceComponent .buildFor(largeFileEditor.getProject(), largeFileEditor.getEditor().getContentComponent()) .addPrimarySearchActions(myPrevOccurrenceAction, myNextOccurrenceAction, new Separator(), myFindAllAction, myFindBackwardAction, myFindForwardAction) .addExtraSearchActions(myToggleCaseSensitiveAction, myToggleWholeWordsAction, myToggleRegularExpression, new DefaultCustomComponentAction( () -> RegExHelpPopup.createRegExLink( new HtmlBuilder().append(HtmlChunk.text("?").bold()).wrapWithHtmlBody().toString(), null, FindUsagesCollector.FIND_IN_FILE)), myStatusTextAction) //.addSearchFieldActions(new RestorePreviousSettingsAction()) .withCloseAction(this::onEscapePressed) .build(); } private void attachListenersToSearchReplaceComponent() { mySearchReplaceComponent.addListener(new SearchReplaceComponent.Listener() { @Override public void searchFieldDocumentChanged() { onSearchParametersChanged(); } @Override public void replaceFieldDocumentChanged() { } @Override public void multilineStateChanged() { } }); } private JBList<SearchResult> createCloseSearchResultsList() { CollectionListModel<SearchResult> model = new CollectionListModel<>(); JBList<SearchResult> list = new JBList<>(model); list.addListSelectionListener(new CloseSearchResultsListSelectionListener(list)); return list; } private void stopSearchTaskIfItExists() { if (lastExecutedCloseSearchTask != null) { lastExecutedCloseSearchTask.shouldStop(); } } private void setNewStatusText(@NlsContexts.StatusText String newStatusText) { myStatusText = newStatusText; myLastTimeStatusTextWasChanged = System.currentTimeMillis(); myIsStatusTextHidden = StringUtil.isEmpty(newStatusText); updateSearchReplaceComponentActions(); } private static int getNextOccurrenceIndexIfCan(boolean directionForward, long currentPageNumber, int caretPageOffset, JBList<SearchResult> listResult) { ListModel<SearchResult> model = listResult.getModel(); int index; SearchResult searchResult; if (model.getSize() == -1) { return -1; } if (listResult.getSelectedIndex() != -1) { index = listResult.getSelectedIndex(); if (directionForward) { index++; } else { index--; } } else { index = 0; while (true) { if (index >= model.getSize()) { if (directionForward) { return -1; } else { return model.getSize() - 1; } } else { searchResult = model.getElementAt(index); if (currentPageNumber > searchResult.startPosition.pageNumber || currentPageNumber == searchResult.startPosition.pageNumber && caretPageOffset >= searchResult.startPosition.symbolOffsetInPage) { index++; } else { break; } } } if (!directionForward) { index--; } } if (index < 0 || index >= model.getSize()) { return -1; } else { return index; } } private final class CloseSearchResultsListSelectionListener implements ListSelectionListener { private final JBList<SearchResult> list; CloseSearchResultsListSelectionListener(JBList<SearchResult> list) { this.list = list; } @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { // it happens when the selecting process is over and the selected position is set finaly SearchResult selectedSearchResult = list.getSelectedValue(); if (selectedSearchResult != null) { largeFileEditor.showSearchResult(selectedSearchResult); } } } } }