Skip to content

Commit

Permalink
return nil for out of bounds positions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jan 3, 2025
1 parent ee7af37 commit 1079f8b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Ligature/UTF16CodePointTextViewTextTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension UTF16CodePointTextViewTextTokenizer {

// moving to the very last position is always allowed and requires no checks
if position + 1 >= maximum {
return maximum
return nil
}

let pos = min(position + 1, maximum - 1)
Expand All @@ -102,7 +102,11 @@ extension UTF16CodePointTextViewTextTokenizer {
case (.character, .storage(.backward)):
guard let storage else { return position }

let pos = max(position - 1, 0)
if position <= 0 {
return nil
}

let pos = position - 1

let charRange = (storage.string as NSString).rangeOfComposedCharacterSequence(at: pos)

Expand Down

0 comments on commit 1079f8b

Please sign in to comment.