mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
RUBY-21803 Dedent is preserving now
IDEA-CR-34795
This commit is contained in:
@@ -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"/>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
top:
|
||||
hello:
|
||||
country: Australia
|
||||
|
||||
<caret>
|
||||
@@ -0,0 +1,4 @@
|
||||
top:
|
||||
hello:
|
||||
country: Australia
|
||||
<caret>
|
||||
@@ -0,0 +1,4 @@
|
||||
top:
|
||||
- country: Australia
|
||||
|
||||
<caret>
|
||||
@@ -0,0 +1,3 @@
|
||||
top:
|
||||
- country: Australia
|
||||
<caret>
|
||||
Reference in New Issue
Block a user