From 36a95cac1044b14f38114f0bafa378cf22107a89 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Tue, 19 Jul 2016 20:55:54 +0300 Subject: [PATCH] Respect possible whitespace line with content --- .../yaml/psi/impl/YAMLBlockScalarImpl.java | 9 ++++----- .../yaml/psi/YAMLScalarContentTest.java | 8 ++++++++ .../org/jetbrains/yaml/psi/data/foldedStyle5.txt | 5 +++++ .../org/jetbrains/yaml/psi/data/foldedStyle5.yml | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.txt create mode 100644 plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.yml diff --git a/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLBlockScalarImpl.java b/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLBlockScalarImpl.java index 57ec25d7116d..f550c10ea378 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLBlockScalarImpl.java +++ b/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLBlockScalarImpl.java @@ -3,6 +3,7 @@ package org.jetbrains.yaml.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.TextRange; import com.intellij.psi.tree.IElementType; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.YAMLTokenTypes; import org.jetbrains.yaml.YAMLUtil; @@ -46,10 +47,6 @@ public abstract class YAMLBlockScalarImpl extends YAMLScalarImpl { assert thisLineStart != -1; result.add(TextRange.create(thisLineStart, child.getTextRange().getEndOffset()).shiftRight(-myStart)); thisLineStart = -1; - - if (node.findChildByType(getContentType(), child.getTreeNext()) == null) { - break; - } } else if (child.getElementType() == YAMLTokenTypes.INDENT) { thisLineStart = child.getStartOffset() + Math.min(indent, child.getTextLength()); @@ -62,7 +59,9 @@ public abstract class YAMLBlockScalarImpl extends YAMLScalarImpl { } } - return result; + final int lastNonEmpty = ContainerUtil.lastIndexOf(result, range -> range.getLength() != 0); + + return lastNonEmpty == -1 ? result : result.subList(0, lastNonEmpty + 1); } protected int locateIndent() { diff --git a/plugins/yaml/testSrc/org/jetbrains/yaml/psi/YAMLScalarContentTest.java b/plugins/yaml/testSrc/org/jetbrains/yaml/psi/YAMLScalarContentTest.java index 14d8054ab308..d5d529003d70 100644 --- a/plugins/yaml/testSrc/org/jetbrains/yaml/psi/YAMLScalarContentTest.java +++ b/plugins/yaml/testSrc/org/jetbrains/yaml/psi/YAMLScalarContentTest.java @@ -57,6 +57,14 @@ public class YAMLScalarContentTest extends LightPlatformCodeInsightFixtureTestCa public void testFoldedStyle4() { doTest(); } + + public void testFoldedStyle5() { + doTest(); + } + + public void testFoldedStyle6() { + doTest(); + } public void testSingleQuote1() { doTest(); diff --git a/plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.txt b/plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.txt new file mode 100644 index 000000000000..42dd5ade042f --- /dev/null +++ b/plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.txt @@ -0,0 +1,5 @@ +foo = bar + + + + diff --git a/plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.yml b/plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.yml new file mode 100644 index 000000000000..b77b62ad3674 --- /dev/null +++ b/plugins/yaml/testSrc/org/jetbrains/yaml/psi/data/foldedStyle5.yml @@ -0,0 +1,16 @@ +> + foo = bar + + + + + + + + + + + + + +