Skip to content

Commit cc15a03

Browse files
committed
Count commonLeadingSpaceCount from larger number to lower
1 parent 2ada7e5 commit cc15a03

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

Core/Sources/SuggestionWidget/SyntaxHighlighting.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func highlightedCodeBlock(
6161
}
6262
return leadingSpaces
6363
}
64-
64+
6565
// Workaround: Splash has a bug that will insert an extra space at the beginning.
6666
let leadingSpaces = leadingSpacesInCode(code)
6767
let leadingSpacesFormatted = leadingSpacesInCode(formatted.string)
@@ -73,7 +73,7 @@ func highlightedCodeBlock(
7373
)
7474
}
7575
// End of workaround.
76-
76+
7777
return formatted
7878
default:
7979
var language = language
@@ -148,15 +148,16 @@ func convertToCodeLines(
148148
let separatedInput = input.components(separatedBy: "\n")
149149
let commonLeadingSpaceCount = {
150150
if !droppingLeadingSpaces { return 0 }
151-
let splitted = separatedInput
151+
let split = separatedInput
152152
var result = 0
153-
outerLoop: for i in [4, 8, 12, 16, 20, 24] {
154-
for line in splitted {
153+
outerLoop: for i in stride(from: 40, through: 4, by: -4) {
154+
for line in split {
155155
if isEmptyLine(line) { continue }
156-
if i >= line.count { break outerLoop }
157-
if !line.hasPrefix(.init(repeating: " ", count: i)) { break outerLoop }
156+
if i >= line.count { continue outerLoop }
157+
if !line.hasPrefix(.init(repeating: " ", count: i)) { continue outerLoop }
158158
}
159159
result = i
160+
break
160161
}
161162
return result
162163
}()

0 commit comments

Comments
 (0)