Merge pull request #1291 from Microsoft/newlines_in_formatting

new lines that were added\removed by rules must always be honored even i...
This commit is contained in:
Vladimir Matveev 2014-11-28 16:13:29 -08:00
commit fe16059214
2 changed files with 25 additions and 6 deletions

View File

@ -701,25 +701,23 @@ module ts.formatting {
applyRuleEdits(rule, previousItem, previousStartLine, currentItem, currentStartLine);
if (rule.Operation.Action & (RuleAction.Space | RuleAction.Delete) && currentStartLine !== previousStartLine) {
lineAdded = false;
// Handle the case where the next line is moved to be the end of this line.
// In this case we don't indent the next line in the next pass.
if (currentParent.getStart(sourceFile) === currentItem.pos) {
lineAdded = false;
dynamicIndentation.recomputeIndentation(/*lineAdded*/ false);
}
}
else if (rule.Operation.Action & RuleAction.NewLine && currentStartLine === previousStartLine) {
lineAdded = true;
// Handle the case where token2 is moved to the new line.
// In this case we indent token2 in the next pass but we set
// sameLineIndent flag to notify the indenter that the indentation is within the line.
if (currentParent.getStart(sourceFile) === currentItem.pos) {
lineAdded = true;
dynamicIndentation.recomputeIndentation(/*lineAdded*/ true);
}
}
if (lineAdded !== undefined) {
dynamicIndentation.recomputeIndentation(lineAdded);
}
// We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line
trimTrailingWhitespaces =
(rule.Operation.Action & (RuleAction.NewLine | RuleAction.Space)) &&

View File

@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />
////module A
////{
//// class B {
//// /*1*/
////}
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
format.setOption("PlaceOpenBraceOnNewLineForFunctions", true);
goTo.marker("1");
edit.insert("}");
verify.currentFileContentIs(
"module A\n\
{\n\
class B\n\
{\n\
}\n\
}"
);