nstextview

Technique on how to format/color NSTextView's string

依然范特西╮ 提交于 2020-01-02 02:33:08
问题 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 = [

How to programmatically add bullet list to NSTextView

好久不见. 提交于 2019-12-31 12:12:07
问题 The question may sound strange but I've been struggling with it for a few days. I have a NSTextView that can display some text with a few formatting options. One of them is the ability to turn on/off the bullet list (the easiest one) for a selection or current row. I know that there is a orderFrontListPanel: method on NSTextView that opens the window with available list parameters to select from and edit (like in TextView when you press Menu->Format->List...). I have already figured out and

Using NSGlyph and memory allocation

こ雲淡風輕ζ 提交于 2019-12-31 04:49:05
问题 in a method to track line breaks frequently , for a NSTextView visibleRect , i am allocating memory for NSGlyph to use NSLayoutManager getGlyphs:range: . should/can i find out how much memory this should be since i have a reference for the range (without affecting layout), and also, what kind of cleanup should happen -- running with ARC ? the code (which runs on a main queue) : NSLayoutManager *lm = [self.textView layoutManager]; NSTextContainer *tc = [self.textView textContainer]; NSRect

Data Detectors in Cocoa

陌路散爱 提交于 2019-12-30 11:16:32
问题 I want to add a data detector in an NSTextField / NSTextView like in Mail (e.g. date, email, URL, etc). Does anyone have an idea how to do this ? I think I saw it in TextEdit's source code but when I checked it was 2005's version and I can't find the new source code. Alex 回答1: You need to set the formatter outlet of the object. Built in formatters are NSDateFormatter and NSNumberFormatter. You can define custom formatters by extending the NSFormatter class. There is a chapter in Aaron

How to find caret position in an NSTextView?

≡放荡痞女 提交于 2019-12-29 04:19:06
问题 I've an NSTextView with with several semi-colon separated strings. I need to find on which of those strings the caret has been placed. How could I do that? 回答1: NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location; 回答2: For Swift 4 let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location 来源: https://stackoverflow.com/questions/1701129/how-to-find-caret-position-in-an-nstextview

NSTextView's Insertion Point draws position exceptions

跟風遠走 提交于 2019-12-24 18:56:48
问题 This should be a Bug, because I can reproduce it with my friends. I just set allowsNonContiguous Layout of NSTextView. layoutManager to true, and that's the problem. In the editor, I first enter N blank lines, that is, press N times to return. Then go back to the second line of our input, and press any key at the moment insertion Point disappears, which will make my insertion Point incorrect. Here is my demo: https://github.com/iiiDD/TextViewDemo 回答1: I had the same problem. I’ve detailed how

NSTextView color and font reset after clearing it

蹲街弑〆低调 提交于 2019-12-24 01:01:59
问题 I set some default font and color to a NSTextView inside of a NSPanel. However, when I clear the view with setString:@"" , not only does the text disappears, but all the default colors/fonts formatting. After I do another setString , the text becomes the default font and black again. Can someone explain why that is and what can I do to remedy it? UPDATED: Thanks for the help and clarification of the issue. I ended up just formatting it again after I setString. [self.txtLog setFont:[NSFont

Create hyperlink to some text in NSTextView

て烟熏妆下的殇ゞ 提交于 2019-12-23 03:14:54
问题 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? 回答1: I haven't done this in

Core Data bindings with subviews and multiple NIBs

若如初见. 提交于 2019-12-23 01:11:17
问题 I have a document-based Core Data app. My main Core Data entity has several string fields, most of which are bound to NSTextFields, but one is bound to an NSTextView. I am using the technique for view switching (with multiple view controllers) as explained in the Hillegass book. All of my subviews are controlled by a ManagedViewController, my subclass of NSViewController that has a managedObjectContext field. My subview exists in a separate nib file. For some reason, the bindings I have set

Appending to NSTextView

旧城冷巷雨未停 提交于 2019-12-22 20:33:00
问题 I've got an NSTask (with an NSPipe set up) running in the background and I want to output the contents, as they're coming in, in an NSTextView ( output ). The code I'm using is : NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithString:s]; //[str addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0, [str length])]; [[output textStorage] appendAttributedString:str]; [output scrollRangeToVisible:NSMakeRange([[output string] length]