Closed WheelaStudio closed 2 years ago
@WheelaStudio Thanks for reporting this. I'm still working on reproducing the bug.
This basic test project worked for me on Big Sur and iOS 15.0 in the simulator:
import SwiftUI
import HighlightedTextEditor
@main
struct TestingiOSApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
// matches text between underscores
let selection = try! NSRegularExpression(pattern: "ян", options: [])
struct ContentView: View {
// snippets grabbed from google
@State var text: String = "Привет Россиянин"
var body: some View {
VStack {
HighlightedTextEditor(text: $text, highlightRules: [
HighlightRule(pattern: selection, formattingRule: TextFormattingRule(key: .foregroundColor, value: UIColor.red))
])
}
}
}
Result:
Could you modify the above code snippet so that it triggers the bug? I have a feeling I'm building the string wrong somehow.
I think it's problem in some files, which text was encoded incorrectly. I will check the program for another week.
Describe the bug For example, if regular expression contains some symbols (e.x: И) from non-latinic alphabets(e.x: Russian) from text, which encoded in UTF-8, an error occurs in file HighlightingTextEditor.swift on 128 line Error text HighlightedTextEditor/HighlightingTextEditor.swift:128: Fatal error: Unexpectedly found nil while unwrapping an Optional value 2021-11-06 18:40:44.187051+0300 TextEditor[13196:2492169] HighlightedTextEditor/HighlightingTextEditor.swift:128: Fatal error: Unexpectedly found nil while unwrapping an Optional value
To Reproduce Steps to reproduce the behavior:
Environment Based on SwiftUI app, running on IOS 15.1