nstextview

NSTextView textDidChange/didChangeText not called for bindings

强颜欢笑 提交于 2019-12-05 18:09:14
I have a custom NSTextView implementation that automatically adjusts the font size so that the text fills the entire view. I overwrote didChangeText to call my font size adjustment method. Works great when the user is editing text, but didChangeText (and the delegate method textDidChange: ) are not called when the text view contents are set via bindings. The font adjustment code needs to run whenever the text is set/changes, not only when it's changed by the user. How can I detect all changes to the text in an NSTextView , even via bindings? Note: If there's a better way to have the text fill

How to get the selected line range of NSTextView?

我们两清 提交于 2019-12-05 17:57:08
How to get the selected line range of NSTextView ? An outline algorithm for you: get the selection - selectedRange create a range of length 1 covering the last char of the selection use lineRangeForRange to obtain a range for the characters making up the line the last char of the selection is in. now work backwards and count - you've got the range of the line containing the last char of the selection, make a range for the last char of the preceding line and use lineRangeForRange to find the range for the preceding line. Repeat this process until you reach the start of the text. You'll have the

Cocoa: Stopping the field editor from auto-completing on space key

风格不统一 提交于 2019-12-05 14:19:59
I have a custom view with several NSTextField controls for which I want to supply custom auto-completions and I have successfully implemented all that using the NSTextFieldDelegate Protocol. The auto-completions are full names or place names, depending on which text field is being edited. The issue is that the auto-completions almost always contain a space character and so if the user is typing something that matches a suggestion, but doesn't want to accept that suggestion, the field editor will accept the suggestion when user presses the space key. I want the field editor to accept the

NSTextView's insertText method is deprecated in OS X v10.11. What is the replacement?

ⅰ亾dé卋堺 提交于 2019-12-05 12:13:29
I saw in the AppKit API Reference that the insertText method is deprecated in OS X v10.11. What am I supposed to use as a replacement? The documentation says - (void)insertText:(id)aString This method is the means by which text typed by the user enters an NSTextView . See the NSInputManager class and NSTextInput protocol specifications for more information. ... In NSTextInput there is a note: IMPORTANT NSTextInput protocol is slated for deprecation. Please use NSTextInputClient protocol, introduced in OS X v10.5, as described in NSTextInputClient Protocol Reference . In NSTextInputClient

Technique on how to format/color NSTextView's string

那年仲夏 提交于 2019-12-05 05:35:20
I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. Some code snippets on how I make a text bold [[textView textStorage] beginEditing]; [[textView textStorage] applyFontTraits:NSFontBoldTrait range:range]; [[textView textStorage] endEditing]; This and also the size changes with [[textView textStorage] beginEditing]; NSFont* font = [[textView textStorage] attribute:NSFontAttributeName atIndex:range.location effectiveRange:nil]; NSFont*

How do I use SPACE instead of TAB in NSTextView

為{幸葍}努か 提交于 2019-12-05 04:52:14
I just know how to modify the tab width in NSTextView NSMutableParagraphStyle *paragraphStyle = [[self defaultParagraphStyle] mutableCopy]; [paragraphStyle setTabStops:[NSArray array]]; [paragraphStyle setDefaultTabInterval: tabWidth]; But, is there any way to use 4 SPACES instead of TAB in NSTextView? John Velman Well, it's late, but I'll post my answer in case some other poor soul is struggling with this. I''ve been struggling with this all day, and finally found the answer at cocoabuilder In summary, what I did was, in my text view delegate: - (BOOL)textView:(NSTextView *)aTextView

NSTextField autocompletion delegate method not called

老子叫甜甜 提交于 2019-12-05 03:50:40
I implemented the following delegate method for NSTextField to add autocompletion support: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index The issue is that this method never gets called. I can verify that the delegate of the NSTextField is set properly because the other delegate methods function as they should. You'll need to get complete: called on the text field's field editor at some point. That's what triggers the completions menu, but it doesn't get called

How to insert a NSButton into a NSTextView? (inline)

依然范特西╮ 提交于 2019-12-04 19:20:52
I have a NSTextView and a custom NSButton. What I want to do is to insert that button (60x16 in size) to the end of the NSTextView. How can I do something like that? I've been trying to search around on how to do this but I'm not getting anywhere. Where should I begin? Thanks I believe this question is pretty similar to yours: Buttons inside an NSTextView / NSTextStorage Quote from the question: how do I get an NSButton to appear inside the text and react to clicks? Note that the issue is not fully solved there, but it seems the OP got a good head start. Hopefully you can take some clues from

Proper way to replace NSTextStorage in NSTextView?

家住魔仙堡 提交于 2019-12-04 18:56:54
问题 I am making some text viewer app. Currently I need very frequent and precise line handling ability, so I want to subclass NSTextStorage class. But I couldn't find any method to set a new text storage to NSTextView . The only method I could find was -[NSLayoutManager replaceTextStorage:] method. But it's confusing whether this is what I was looking for. Because it seems just replace text storage of linked NSLayoutManagers instead of NSTextView. I also considered subclassing NSTextView and

Padding around an NSTextView in an NSScrollView

Deadly 提交于 2019-12-04 15:57:20
问题 I'd like to provide a few pixels of padding around an NSTextView inside of an NSScrollView. I've reviewed this post and using setTextContainerInset does the trick for the left, right, and bottom margins. But as soon as the text scrolls the top buffer is lost. Same thing with overriding textContainerOrigin. Another answer in that post states: The way TextEdit does it (when in Wrap to Page mode) is to put the text view inside of a larger view, and set that larger view as the document view of