RUBY-21803 Dedent is preserving now

IDEA-CR-34795
This commit is contained in:
Alexey Merkulov
2018-07-10 19:54:34 +03:00
parent 19990f6765
commit 4e2dc0f604
7 changed files with 59 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
<additionalTextAttributes scheme="Darcula" file="colorSchemes/YAMLDarcula.xml"/>
<lang.formatter language="yaml" implementationClass="org.jetbrains.yaml.formatter.YAMLFormattingModelBuilder"/>
<enterHandlerDelegate implementation="org.jetbrains.yaml.formatter.YAMLEnterAtIndentHandler" order="first"/>
<lang.parserDefinition language="yaml" implementationClass="org.jetbrains.yaml.YAMLParserDefinition"/>
<lang.commenter language="yaml" implementationClass="org.jetbrains.yaml.YAMLCommenter"/>
<lang.syntaxHighlighterFactory language="yaml" implementationClass="org.jetbrains.yaml.YAMLSyntaxHighlighterFactory"/>

View File

@@ -0,0 +1,34 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.yaml.formatter;
import com.intellij.codeInsight.editorActions.BackspaceHandler;
import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegateAdapter;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.yaml.psi.YAMLFile;
public class YAMLEnterAtIndentHandler extends EnterHandlerDelegateAdapter {
@Override
public Result preprocessEnter(@NotNull PsiFile file,
@NotNull Editor editor,
@NotNull Ref<Integer> caretOffset,
@NotNull Ref<Integer> caretAdvance,
@NotNull DataContext dataContext,
EditorActionHandler originalHandler) {
//if (true) return Result.Continue;
if (!(file instanceof YAMLFile)) {
return Result.Continue;
}
// honor dedent (RUBY-21803)
// The solutions is copied from com.jetbrains.python.editor.PyEnterAtIndentHandler
if (BackspaceHandler.isWhitespaceBeforeCaret(editor)) {
return Result.DefaultSkipIndent;
}
return Result.Continue;
}
}

View File

@@ -42,6 +42,14 @@ public class YAMLTypingTest extends LightPlatformCodeInsightFixtureTestCase {
doTest("\n");
}
public void testPreserveDedent() {
doTest("\n");
}
public void testPreserveDedentAfterInlinedMap() {
doTest("\n");
}
@SuppressWarnings("SameParameterValue")
private void doTest(String insert) {
String testName = getTestName(true);

View File

@@ -0,0 +1,5 @@
top:
hello:
country: Australia
<caret>

View File

@@ -0,0 +1,4 @@
top:
hello:
country: Australia
<caret>

View File

@@ -0,0 +1,4 @@
top:
- country: Australia
<caret>

View File

@@ -0,0 +1,3 @@
top:
- country: Australia
<caret>