nstextview

NSTextField autocompletion delegate method not called

时光怂恿深爱的人放手 提交于 2019-12-06 22:34:07
问题 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. 回答1: You'll need to get complete: called on the

Create hyperlink to some text in NSTextView

匆匆过客 提交于 2019-12-06 16:44:33
I can create a hyperlink to some url in an NSTextView using the "Link Panel". Or I can add a link manually using the NSLinkAttributeName attribute of NSAttributedString. I don't want to make a hyperlink to some external url though, I want to be able to create a hyperlink to some text within the NSTextView. Do you know how in Pages you can set some text as a Bookmark, and then you can make a hyperlink to that bookmark? Any ideas or examples of how to go about that? I haven't done this in a while so take this with a grain of salt but it goes something like: You need to define a protocol for you

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

自作多情 提交于 2019-12-06 15:34:16
问题 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 回答1: 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

Set the background color of selected text in NSTextView?

隐身守侯 提交于 2019-12-06 11:47:20
I am trying to change the background color of a portion of text that is selected by the user to a different color (to add a highlight) to the text. Now I have tried the: (void)setSelectedTextAttributes:(NSDictionary *)attributes method but that only changes the background color of the selection. I need the to change the background color of text so that it stays highlighted. As you've discovered, the selected text attributes only apply to the text while it's selected. If you want to add some attributes to the selected text that persist, you'll need to apply those attributes to the underlying

How to convert formatted content of NSTextView to string

久未见 提交于 2019-12-06 10:11:34
问题 I need transfer content of NSTextView from Mac app to iOS app. I'm using XML as transfered file format. So I need to save content of NSTextView (text, fonts, colors atd.) as a string. Is there any way how to do that? 回答1: One way to do this is to archive the NSAttributedString value. Outline sample code typed directly into answer: NSTextView *myTextView; NSString *myFilename; ... [NSKeyedarchiver archiveRootObject:myTextStorage.textStorage toFile:myFilename]; To read it back: myTextView

Growing NSTextView to fit contents is clipping last line of text

本小妞迷上赌 提交于 2019-12-06 03:49:00
问题 I'm trying to create an NSTextView that grows vertically as the user types and scrolls once the height has reached a maximum. This is similar to the text view in Messages works. My first attempt uses the delegate to listen for text changes and adjust the height constraint associated with the NSTextView's scroll view: - (void)textDidChange:(NSNotification *)notification { NSTextView *textView = self.textView; NSRect usedRect = [textView.textContainer.layoutManager usedRectForTextContainer

NSLineBreakByTruncatingTail scrolls text when set as a paragraph style in NSTextView

你。 提交于 2019-12-06 03:18:59
I have a NSTextView , which is supposed to be fixed size. When the text comes to the bottom line and to the right edge of the designated frame I need to set the NSLineBreakByTruncatingTail in order to present user with elliptic signs and disable further typing. When I do this through setting a paragraph style on textStorage of NSTextView the text scrolls up and I see only the last line with elliptic signs in the end. My question is how to prevent NSTextView from scrolling when changing its lineBreakMode ? Thanks, Nava EDIT: (added screenshots) Before: After: Now here's the code that does it: -

Get selection (highlighted text) string from NSTextView Objective-C

落花浮王杯 提交于 2019-12-05 23:56:46
How can I get the selected text's string from a NSTextView as an NSString ? Your help is greatly appreciated. Since NSTextView is a subclass of NSText, you can use NSText instance methods to figure out the selected string like so: NSString *selected = [[myTextView string] substringWithRange:[myTextView selectedRange]]; An NSText can have more than only one selection. Check it out with TextEditapp: select a string with the mouse while pressing CMD. So you can select as many strings as you want. Therefore I think, a more common solution is to use: NSArray *ranges = [myTextView selectedRanges];

How to insert emoji into NSTextView without shifting the line down?

痴心易碎 提交于 2019-12-05 23:56:17
How do I insert emoji into an NSTextView without moving the line down? If I insert an emoji character into an NSTextView , the whole line will shift down a couple pixels. If I remove the emoji character, it will move back up to its original position. On the other hand, if I insert an emoji into an NSTextField , the line doesn't move at all, even when the text in the line is the same font and size as it was in the NSTextView . You can see this behavior in TextEdit. When you are typing in the main editor area (an NSTextView ), emoji make the lines move down. When you are typing in the Find

Automatic Link Detection not working in NSTextView after programmatically setting text

半腔热情 提交于 2019-12-05 19:01:14
问题 I have an NSTextView with automatic link detection enabled. When I set the text programmatically [myTextView setString:@"http://google.com"] it doesn't automatically show the link. If I type anything into the text view it will add the link. I want it to add the link 回答1: Had to spent some time searching for solution, but could not find it anywhere. You do not need any third party libraries. Cocoa will do it for you. checkTextInDocument: works only on editable textViews (Apple forgot to