Skip to content

Commit

Permalink
🐛 Fix a crash when having a blank space before a node (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
qeude authored Feb 19, 2024
1 parent b2ae138 commit 192ecb8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/SwiftDown/MarkdownEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class MarkdownEngine {
let fromIdx = text.utf8.index(text.utf8.startIndex, offsetBy: s)
let range =
text.utf8
.index(text.utf8.startIndex, offsetBy: e, limitedBy: text.utf8.endIndex)
.index(text.utf8.startIndex, offsetBy: max(0, e), limitedBy: text.utf8.endIndex)
.flatMap {
if ($0 < text.utf8.endIndex ) {
if ($0 < text.utf8.endIndex && $0 > fromIdx) {
let range = NSRange(fromIdx...$0, in: text)
return NSRange(location: range.location + offset, length: range.length)
} else {
Expand Down

0 comments on commit 192ecb8

Please sign in to comment.