IDEA-196178 Join Lines on selected text also joins not selected text

This commit is contained in:
Tagir Valeev
2019-02-01 15:10:24 +07:00
parent 9e2e512f6b
commit 1bc7264b58
4 changed files with 31 additions and 1 deletions
@@ -0,0 +1,14 @@
class Foo {
void test() {
int a = 2;
int b = 2;
<selection>if (a == b){
if (a > b){
System.out.println();
}
}</selection>
System.out.println();
}
}
@@ -0,0 +1,10 @@
class Foo {
void test() {
int a = 2;
int b = 2;
if (a == b && a > b) System.out.println();
System.out.println();
}
}
@@ -56,6 +56,7 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
public void testIfChainPolyadic() { doTest(); }
public void testIfChainNoBraces() { doTest(); }
public void testIfChainElse() { doTest(); }
public void testIfChainSelection() { doTest(); }
public void testSCR3493() {
CommonCodeStyleSettings settings = getJavaSettings();
@@ -88,11 +88,16 @@ public class JoinLinesHandler extends EditorActionHandler {
Ref<Integer> caretRestoreOffset = new Ref<>(-1);
CodeEditUtil.setNodeReformatStrategy(node -> node.getTextRange().getStartOffset() >= startReformatOffset);
try {
for (int count = 0; count < lineCount; count++) {
int count = 0;
while (count < lineCount) {
indicator.checkCanceled();
indicator.setFraction(((double)count) / lineCount);
int beforeLines = doc.getLineCount();
ProgressManager.getInstance().executeNonCancelableSection(
() -> doJoinTwoLines(doc, project, docManager, psiFile, line, caretRestoreOffset));
int afterLines = doc.getLineCount();
// Single Join two lines procedure could join more than two (e.g. if it removes braces)
count += Math.max(beforeLines - afterLines, 1);
}
}
finally {