|
13 | 13 | @class MMTextViewHelper; |
14 | 14 |
|
15 | 15 |
|
| 16 | +/// The main text view that manages drawing Vim's content using Core Text, and |
| 17 | +/// handles input. We are using this instead of NSTextView because of the |
| 18 | +/// custom needs in order to draw Vim's texts, as we don't have access to the |
| 19 | +/// full contents of Vim, and works more like a smart terminal to Vim. |
| 20 | +/// |
| 21 | +/// Currently the rendering is done in software via Core Text, but a future |
| 22 | +/// extension will add support for Metal rendering which probably will require |
| 23 | +/// splitting this class up. |
| 24 | +/// |
| 25 | +/// Since this class implements text rendering/input using a custom view, it |
| 26 | +/// implements NSTextInputClient, mostly for the following needs: |
| 27 | +/// 1. Text input. This is done via insertText / doCommandBySelector. |
| 28 | +/// 2. Input methods (e.g. for CJK). This is done via the marked text and the |
| 29 | +/// other APIs like selectedRange/firstRectForCharacterRange/etc. |
| 30 | +/// 3. Support native dictionary lookup (quickLookWithEvent:) when the user |
| 31 | +/// wants to. This mostly involves implementing the attributeSubstring / |
| 32 | +/// firstRectForCharacterRange / characterIndexForPoint APIs. |
| 33 | +/// There is an inherent difficulty to implementing NSTextInputClient |
| 34 | +/// 'correctly', because it assumes we have an entire text storage with |
| 35 | +/// indexable ranges. However, we don't have full access to Vim's internal |
| 36 | +/// storage, and we are represening the screen view instead in row-major |
| 37 | +/// indexing, but this becomes complicated when we want to implement marked |
| 38 | +/// texts. We the relevant parts for comments on how we hack around this. |
16 | 39 | @interface MMCoreTextView : NSView < |
17 | | - NSTextInput |
| 40 | + NSTextInputClient |
18 | 41 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 |
19 | 42 | , NSFontChanging |
20 | 43 | , NSMenuItemValidation |
|
122 | 145 | // NSTextView methods |
123 | 146 | // |
124 | 147 | - (void)keyDown:(NSEvent *)event; |
125 | | -- (void)insertText:(id)string; |
| 148 | + |
| 149 | +// |
| 150 | +// NSTextInputClient methods |
| 151 | +// |
| 152 | +- (void)insertText:(id)string replacementRange:(NSRange)replacementRange; |
126 | 153 | - (void)doCommandBySelector:(SEL)selector; |
| 154 | +- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange; |
| 155 | +- (void)unmarkText; |
| 156 | +- (NSRange)selectedRange; |
| 157 | +- (NSRange)markedRange; |
| 158 | +- (BOOL)hasMarkedText; |
| 159 | +- (nullable NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange; |
| 160 | +- (nonnull NSArray<NSAttributedStringKey> *)validAttributesForMarkedText; |
| 161 | +- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange; |
| 162 | +- (NSUInteger)characterIndexForPoint:(NSPoint)point; |
127 | 163 |
|
128 | 164 | // |
129 | 165 | // NSTextContainer methods |
|
0 commit comments