Skip to content

Commit

Permalink
Fix indentation problem with onEnterRule
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr authored and mickaelistria committed Sep 7, 2022
1 parent e848424 commit 887ac28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 887ac28

Please sign in to comment.