nstextstorage

ios - Replace/delete characters [• ] in UITextView on Enter

好久不见. 提交于 2021-01-28 05:17:30
问题 I have a UITextView with a custom NSTextStorage, where I add a list bullet, after each Enter, if the prior line starts with a list bullet. When a user Enter and there is only a list bullet in the beginning of the line where the cursor is, I remove the list bullet and stay on that line. The first function works as expected. But I have a hard time figuring out how to remove the list bullet. if prefix.isEmpty { let text = string.split(separator: "\n") let next = NSMakeRange(textView

Hide Markdown Characters with NSLayoutManager in Swift

橙三吉。 提交于 2020-08-01 09:05:10
问题 I am working on a rich text editor in a Mac app that uses Markdown syntax. I use NSTextStorage to watch for matches in Markdown syntax, then apply styles to the NSAttributedString in real time like this: At this point, I'm already in way over my head on this stuff, but I'm excited to be making progress. :) This tutorial was very helpful. As a next step, I want to hide the Markdown characters when the NSTextView 's string is rendered. So in the example above, once the last asterisk is typed, I

NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) moves selection

泄露秘密 提交于 2019-12-22 11:16:33
问题 I'm trying to implement a syntax-coloring text editor that also does things like insert whitespace at the start of a new line for you, or replace text with text attachments. After perusing the docs again after a previous implementation had issues with undoing, it seems like the recommended bottleneck for this is NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) method (which states that Delegates can change the characters or attributes. , whereas

How to extend NSTextStorage?

▼魔方 西西 提交于 2019-12-22 03:52:59
问题 According to documentation, I try to subclass NSTextStorage and use it in text view: /* NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It implements change management (beginEditing/endEditing), verification of attributes, delegate handling, and layout management notification. The one aspect it does not implement is the actual attributed string storage --- this is left up to the subclassers, which need to override the two NSMutableAttributedString primitives: - (void

In my programmatically instantiated UITextView (initialized with NSTextContainer) the .text property is always nil

試著忘記壹切 提交于 2019-12-21 06:15:05
问题 [UPDATED w/ SOLUTION and WORKING CODE in bottom section] In -viewDidLoad I alloc, initWithFrame: Add myTextView to subView Set some basic properties (alignment, background color, text color, etc) Set default text The .text does not appear. myTextView appears (as indicated by background color), set breakpoint, it has a frame, memory, etc. Everything looks right. myTextView looks good, but the .text is nil. I change it, set it, update it. No matter what the .text remains nil. I have read the