From 887ac28a32c4e247bc7c5bad241f3dade9980dbd Mon Sep 17 00:00:00 2001 From: azerr Date: Wed, 7 Sep 2022 13:49:20 +0200 Subject: [PATCH] Fix indentation problem with onEnterRule Signed-off-by: azerr --- .../LanguageConfigurationAutoEditStrategy.java | 13 +++++++------ .../internal/utils/TextUtils.java | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationAutoEditStrategy.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationAutoEditStrategy.java index 7732a4d9e..35ee25d41 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationAutoEditStrategy.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationAutoEditStrategy.java @@ -185,15 +185,14 @@ private void onEnter(final IDocument document, final DocumentCommand command) { if (!registry.shouldEnterAction(document, command.offset, contentType)) { continue; } + // https://github.com/microsoft/vscode/blob/bf63ea1932dd253745f38a4cbe26bb9be01801b1/src/vs/editor/common/cursor/cursorTypeOperations.ts#L309 final var enterAction = registry.getEnterAction(document, command.offset, contentType); if (enterAction != null) { - final String indentation = TextUtils.getIndentationFromWhitespace(enterAction.indentation, - getTabSpaces()); final String delim = command.text; switch (enterAction.indentAction) { case None: { // Nothing special - final String increasedIndent = normalizeIndentation(indentation + enterAction.appendText); + final String increasedIndent = normalizeIndentation(enterAction.indentation + enterAction.appendText); final String typeText = delim + increasedIndent; command.text = typeText; @@ -203,7 +202,7 @@ private void onEnter(final IDocument document, final DocumentCommand command) { } case Indent: { // Indent once - final String increasedIndent = normalizeIndentation(indentation + enterAction.appendText); + final String increasedIndent = normalizeIndentation(enterAction.indentation + enterAction.appendText); final String typeText = delim + increasedIndent; command.text = typeText; @@ -213,8 +212,8 @@ private void onEnter(final IDocument document, final DocumentCommand command) { } case IndentOutdent: { // Ultra special - final String normalIndent = normalizeIndentation(indentation); - final String increasedIndent = normalizeIndentation(indentation + enterAction.appendText); + final String normalIndent = normalizeIndentation(enterAction.indentation); + final String increasedIndent = normalizeIndentation(enterAction.indentation + enterAction.appendText); final String typeText = delim + increasedIndent + delim + normalIndent; command.text = typeText; @@ -223,6 +222,8 @@ private void onEnter(final IDocument document, final DocumentCommand command) { break; } case Outdent: + final String indentation = TextUtils.getIndentationFromWhitespace(enterAction.indentation, + getTabSpaces()); final String outdentedText = outdentString( normalizeIndentation(indentation + enterAction.appendText)); diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java index 9621a1925..78b9bfc16 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java @@ -179,7 +179,7 @@ public static TabSpacesInfo getTabSpaces(@Nullable final ITextViewer viewer) { return new TabSpacesInfo(tabSize, true); } } - return new TabSpacesInfo(-1, false); + return new TabSpacesInfo(4, false); } }