@Nullable public TextRange performReplace( final FindResult occurrence, final String replacement, final Editor editor) { if (myReplaceDenied || !ReadonlyStatusHandler.ensureDocumentWritable(editor.getProject(), editor.getDocument())) return null; FindModel findModel = mySearchResults.getFindModel(); TextRange result = FindUtil.doReplace( editor.getProject(), editor.getDocument(), findModel, new FindResultImpl(occurrence.getStartOffset(), occurrence.getEndOffset()), replacement, true, new ArrayList<Pair<TextRange, String>>()); myLivePreview.inSmartUpdate(); mySearchResults.updateThreadSafe(findModel, true, result, mySearchResults.getStamp()); return result; }
@Override public String getStringToReplace(Editor editor, FindResult findResult) { if (findResult == null) { return null; } String foundString = editor.getDocument().getText(findResult); String documentText = editor.getDocument().getText(); FindModel currentModel = mySearchResults.getFindModel(); String stringToReplace = null; if (currentModel != null) { if (currentModel.isReplaceState()) { FindManager findManager = FindManager.getInstance(editor.getProject()); try { stringToReplace = findManager.getStringToReplace( foundString, currentModel, findResult.getStartOffset(), documentText); } catch (FindManager.MalformedReplacementStringException e) { return null; } } } return stringToReplace; }