From 7b5b5f20d6dbd567760a7c664a4623831f57d223 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Wed, 14 Sep 2016 13:24:15 +0200 Subject: [PATCH] IDEA-159341 Replace in file: Regex for start of line matches twice on empty lines --- .../testSrc/com/intellij/find/FindManagerTest.java | 8 ++++++++ platform/lang-impl/src/com/intellij/find/FindUtil.java | 1 + 2 files changed, 9 insertions(+) diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java index 0419033fdc23..4e946bdd4563 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java @@ -927,6 +927,14 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { assertSize(2, findUsages(findModel)); } + public void testProperHandlingOfEmptyLinesWhenReplacingWithRegExp() throws Exception { + doTestRegexpReplace( + "foo\n\n\n", + "^", + "// ", + "// foo\n// \n// \n"); + } + private void runAsyncTest(String text, FindModel findModel) throws InterruptedException { final Ref result = new Ref<>(); final CountDownLatch progressStarted = new CountDownLatch(1); diff --git a/platform/lang-impl/src/com/intellij/find/FindUtil.java b/platform/lang-impl/src/com/intellij/find/FindUtil.java index 58f026d50963..13700a68f07c 100644 --- a/platform/lang-impl/src/com/intellij/find/FindUtil.java +++ b/platform/lang-impl/src/com/intellij/find/FindUtil.java @@ -570,6 +570,7 @@ public class FindUtil { TextRange textRange = doReplace(project, document, model, result, toReplace, toPrompt, rangesToChange); replaced = true; newOffset = model.isForward() ? textRange.getEndOffset() : textRange.getStartOffset(); + if (textRange.isEmpty()) ++newOffset; occurrences++; } else {