From 372a4e99a37f3d1b0a7ff18999de41ab12741f3e Mon Sep 17 00:00:00 2001 From: Hiro Date: Thu, 16 May 2024 18:08:50 +0800 Subject: [PATCH] --bugfix=fix indent size error when EnterAction object reuse. --- .../textmate/TextMateNewlineHandler.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/language-textmate/src/main/java/io/github/rosemoe/sora/langs/textmate/TextMateNewlineHandler.java b/language-textmate/src/main/java/io/github/rosemoe/sora/langs/textmate/TextMateNewlineHandler.java index d6ffe8177..7d75e5789 100644 --- a/language-textmate/src/main/java/io/github/rosemoe/sora/langs/textmate/TextMateNewlineHandler.java +++ b/language-textmate/src/main/java/io/github/rosemoe/sora/langs/textmate/TextMateNewlineHandler.java @@ -414,24 +414,27 @@ public CompleteEnterAction getEnterAction(final Content content, final CharPosit return null; } + final EnterAction.IndentAction indentAction = enterResult.indentAction; + String appendText = enterResult.appendText; + final Integer removeText = enterResult.removeText; // Here we add `\t` to appendText first because enterAction is leveraging // appendText and removeText to change indentation. - if (enterResult.appendText == null) { - if (enterResult.indentAction == EnterAction.IndentAction.Indent || enterResult.indentAction == EnterAction.IndentAction.IndentOutdent) { - enterResult.appendText = "\t"; + if (appendText == null) { + if (indentAction == EnterAction.IndentAction.Indent + || indentAction == EnterAction.IndentAction.IndentOutdent) { + appendText = "\t"; } else { - enterResult.appendText = ""; + appendText = ""; } - } else if (enterResult.indentAction == EnterAction.IndentAction.Indent) { - enterResult.appendText = "\t" + enterResult.appendText; + } else if (indentAction == EnterAction.IndentAction.Indent) { + appendText = "\t" + appendText; } - final var removeText = enterResult.removeText; if (removeText != null) { indentation = indentation.substring(0, indentation.length() - removeText); } - return new CompleteEnterAction(enterResult.indentAction, enterResult.appendText, enterResult.removeText, indentation); + return new CompleteEnterAction(indentAction, appendText, removeText, indentation); }