Skip to content

Commit 9c65aff

Browse files
committed
Merge branch 'pull31'
2 parents 090d1a5 + 9bf9983 commit 9c65aff

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/vbaDeveloper.xlam/Formatter.bas

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Private Const BEG_END_ELSEIF = "ElseIf"
6262
Private Const BEG_END_CASE = "Case "
6363

6464
Private Const THEN_KEYWORD = "Then"
65-
Private Const LINE_CONTINUATION = "_"
65+
Private Const LINE_CONTINUATION = " _"
6666

6767
Private Const INDENT = " "
6868

@@ -199,8 +199,9 @@ Public Sub formatCode(codePane As codeModule)
199199
Dim lineCount As Integer
200200
lineCount = codePane.CountOfLines
201201

202-
Dim indentLevel As Integer, nextLevel As Integer, levelChange As Integer
202+
Dim indentLevel As Integer, nextLevel As Integer, levelChange As Integer, isPrevLineContinuated as Boolean
203203
indentLevel = 0
204+
isPrevLineContinuated = False
204205
Dim lineNr As Integer
205206
For lineNr = 1 To lineCount
206207
Dim line As String
@@ -231,7 +232,10 @@ Public Sub formatCode(codePane As codeModule)
231232
line = indentation(indentLevel) + line
232233
indentLevel = nextLevel
233234
End If
234-
Call codePane.ReplaceLine(lineNr, line)
235+
If Not isPrevLineContinuated Then
236+
Call codePane.ReplaceLine(lineNr, line)
237+
EndIf
238+
isPrevLineContinuated = isLineContinuated(line)
235239
Next
236240
Exit Sub
237241
formatCodeError:
@@ -261,7 +265,7 @@ Private Function indentChange(ByVal line As String) As Integer
261265
Set w = vbaWords
262266

263267
If isEqual(line, ONEWORD_END_FOR) Or _
264-
isEqual(line, ONEWORD_END_LOOP) Then
268+
lineStartsWith(ONEWORD_END_LOOP, line) Then
265269
indentChange = -1
266270
GoTo hell
267271
End If
@@ -321,6 +325,13 @@ Private Function isOneLineIfStatemt(line As String) As Boolean
321325
End Function
322326

323327

328+
Private Function isLineContinuated(line As String) As Boolean
329+
Dim trimmedLine As String
330+
trimmedLine = TrimComments(line)
331+
isLineContinuated = lineEndsWith(LINE_CONTINUATION, trimmedLine)
332+
End Function
333+
334+
324335
' Trims trailing comments (and whitespace before a comment) from a line of code
325336
Private Function TrimComments(ByVal line As String) As String
326337
Dim c As Long

0 commit comments

Comments
 (0)