Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Smart indentation issue - Too much whitespace.

The indentation algorithm needs to find the previous line's indentation amount.  It has to scan until it finds a beginning of a line.  The line delimiter it searches for is "\r\n" which is incorrect if the line ends only a "\n".

Closes #49
  • Loading branch information...
commit 06194d2be7ecb4ae459f717455f4c99ef2e00dc7 1 parent 80a32a5
@jmis jmis authored
View
2  ClojureExtension.Editor/AutoIndent/ClojureSmartIndent.cs
@@ -36,7 +36,7 @@ public int GetDesiredIndentation(int position, EditorOptions options)
int previousLineLength = 0;
IndexTokenNode startOfLine = firstOpenBrace.Previous();
- while (startOfLine != null && (startOfLine.IndexToken.Token.Type != TokenType.Whitespace || (startOfLine.IndexToken.Token.Type == TokenType.Whitespace && !startOfLine.IndexToken.Token.Text.Contains("\r\n"))))
+ while (startOfLine != null && (startOfLine.IndexToken.Token.Type != TokenType.Whitespace || (startOfLine.IndexToken.Token.Type == TokenType.Whitespace && !startOfLine.IndexToken.Token.Text.Contains("\n"))))
{
previousLineLength += startOfLine.IndexToken.Token.Length;
startOfLine = startOfLine.Previous();
View
13 ClojureExtension.Tests/Editor/AutoIndent/ClojureSmartIndentTests.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Collections.Generic;
using ClojureExtension.Parsing;
using ClojureExtension.Utilities;
using Microsoft.ClojureExtension.Editor.AutoIndent;
@@ -80,5 +77,13 @@ public void ShouldIndentByOneAfterTheOpeningBraceForVectors()
_tokenizedBufferEntity.CurrentState = _tokenizer.Tokenize(input);
Assert.AreEqual(input.LastIndexOf("[") + 1, _clojureSmartIndent.GetDesiredIndentation(input.IndexOf("\n") + 1, _defaultOptions));
}
+
+ [TestMethod]
+ public void DropsExistingLineDownWhileMaintainingIndentAndIndentsTheCorrectAmountForNewLine()
+ {
+ string input = "(ns program (:gen-class))\n\n(defn -main [& args] (println \"Hello world\"))";
+ _tokenizedBufferEntity.CurrentState = _tokenizer.Tokenize(input);
+ Assert.AreEqual(4, _clojureSmartIndent.GetDesiredIndentation(input.IndexOf("(println") - 1, _defaultOptions));
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.