Skip to content

Commit

Permalink
Merge pull request #908 from sschaef/t1002400-match-error-in-save-action
Browse files Browse the repository at this point in the history
Handle single empty line in `RemoveDuplicatedEmptyLines` save action
  • Loading branch information
kiritsuku committed Mar 30, 2015
2 parents 677071e + 91d9114 commit 923d2fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -41,4 +41,9 @@ class RemoveDuplicatedEmptyLinesTest extends DocumentSaveActionTests {
| }
|}
|""".stripMargin after SaveEvent

@Test
def do_not_throw_exception_on_single_empty_line() = """|^
|class X""".stripMargin becomes """|^
|class X""".stripMargin after SaveEvent
}
Expand Up @@ -26,14 +26,17 @@ trait RemoveDuplicatedEmptyLines extends SaveAction with DocumentSupport {
case (r, _) => r.trimRight(document).length == 0
}

val removedLines = emptyLines.sliding(2) flatMap {
def removedLines = emptyLines.sliding(2) flatMap {
case Seq((l1, i1), (l2, i2)) =>
if (i1+1 == i2)
Seq(Remove(l1.start, l1.end+1))
else
Seq()
}

removedLines.toList
if (emptyLines.lengthCompare(1) == 0)
Nil
else
removedLines.toList
}
}

0 comments on commit 923d2fd

Please sign in to comment.