nstextstorage

Modifying NSTextStorage causes insertion point to move to the end of the line

帅比萌擦擦* 提交于 2019-12-01 03:40:27
I've got an NSTextView subclass acting as its NSTextStorage delegate. I'm trying to do 2 things: Highlight the text in some ways Evaluate the text and then append the answer to the textview. I'm doing this in two different methods, both invoked by the - (void)textStorageWillProcessEditing:(NSNotification *)notification delegate callback. I can do the syntax highlighting just fine, but when it comes to appending my answer, the insertion point jumps to the end of the line and I don't really know why. My evaluate method looks like the following: NSString *result = ..; NSRange lineRange = [

How to Initialize NSTextStorage with a String in Swift

余生颓废 提交于 2019-11-29 11:04:06
In order to break another problem down into smaller parts, I am trying to set up all the TextKit components. However, I am getting an crash after changing how I initialize NSTextStorage . For testing purposes I have simplified the project to the following: import UIKit class ViewController3: UIViewController { @IBOutlet weak var textView: UITextView! @IBOutlet weak var myTextView: MyTextView! override func viewDidLoad() { super.viewDidLoad() let container = NSTextContainer(size: myTextView.bounds.size) let layoutManager = NSLayoutManager() let textStorage = NSTextStorage(string: "This is a

How to Initialize NSTextStorage with a String in Swift

霸气de小男生 提交于 2019-11-28 04:08:48
问题 In order to break another problem down into smaller parts, I am trying to set up all the TextKit components. However, I am getting an crash after changing how I initialize NSTextStorage . For testing purposes I have simplified the project to the following: import UIKit class ViewController3: UIViewController { @IBOutlet weak var textView: UITextView! @IBOutlet weak var myTextView: MyTextView! override func viewDidLoad() { super.viewDidLoad() let container = NSTextContainer(size: myTextView