nstextview

How to make NSTextView balance delimiters with a double-click?

≯℡__Kan透↙ 提交于 2020-01-17 12:38:51
问题 It's common to have a text editor for code or other structured content that balances delimiters of some sort; when you double click on a { it selects to the matching }, or similarly for ( ) pairs, [ ] pairs, etc. How can I implement this behavior in NSTextView in Cocoa/Obj-C? (I will be posting an answer momentarily, since I found nothing on SO about this and spent today implementing a solution. Better answers are welcome.) ADDENDUM: This is not the same as this question, which is about

Getting formatted string from NSTextView

痞子三分冷 提交于 2020-01-17 03:19:05
问题 I am creating an OSX app with NSTextView inside NSScrollView . Using the FormatMenuItem I can modify the text in that NSTextView to Bold, italic etc. But when I get the values using (NSTextViewOutlet.String) I cannot get the modified string, that is the string contain bold and italic characters. 回答1: By using below code solve my problem.and i use NSTextField instead of NSTextView. let str = txt_outlet.attributedStringValue 来源: https://stackoverflow.com/questions/40358955/getting-formatted

How to loop through subviews in order to get the text of NSTextViews

半城伤御伤魂 提交于 2020-01-16 11:56:58
问题 I have a NSView which contains several instances of NSTextView. I would like to get the content (string) of each instance. So far, I have this (this code does not compile) : for(NSView *view in [self subviews]) { NSLog(@"class: %@ ", [view className]); if([view isKindOfClass:[NSTextView class]]) NSLog(@"[view string] %@",[view string]);} At this point, I expect to be able to send the string message to view which is an instance of NSTextView, but: Error message: No visible @interface for

NSTextView enclosing scroll view jumps on spacebar

为君一笑 提交于 2020-01-06 14:01:19
问题 I have an odd behavior with my app and I don't know where it comes from. I have implemented a NSScanner for a text view content that works very well. The scanner works in conjunction with the text storage to set attributes on the text storage string via text view delegate methods. However, each time I enter a space, the enclosing scroll view scrolls back to the top of the text view. Can anyone give me a hint where this comes from ? 回答1: Probably not much hassle for those more experienced than

How do I set a Custom NSFormatter to a NSTextView?

依然范特西╮ 提交于 2020-01-06 07:55:26
问题 I have a NSTextView and i have a custom NSFormatter that limits the string length. But how do i " [_textView setFormatter:customFormatter] " on a NSTextView ? I can't find how to do that. Example code would be appreciated! 回答1: It's not possible to use a custom NSFormatter with a NSTextView. (That appears to be the province of NSControl, of which NSTextField is a subclass.) However, it is possible to set up a delegate for your text view's text storage ( NSTextStorage ), and implement

NSTextView caret size sometimes ignored

邮差的信 提交于 2020-01-05 03:51:25
问题 I'm changing the caret size using - (void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag . Anyway, when I move selection, the caret momentarily changes back to its default size. Is there another method that draws the caret that I need to override? What I'm currently doing : - (void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag { aRect.origin.y -= 1; aRect.origin.x -= 1; aRect.size.width += 1; aRect.size.height += 1;

NSPoint/NSRect from character in NSTextView

╄→гoц情女王★ 提交于 2020-01-04 04:41:07
问题 So I am trying to get either an NSPoint or NSRect corresponding with the location of a specific character in an NSTextView. This is what I have so far (that isn't working very well, the results seem kind of unpredictable. NSRange theTextRange = [[theTextView layoutManager] glyphRangeForCharacterRange:[theTextStorage editedRange] actualCharacterRange:NULL]; NSRect theTextRect = [[theTextView layoutManager] boundingRectForGlyphRange:theTextRange inTextContainer:[theTextView textContainer]]; 回答1

NSTextView customizing double click selection

╄→尐↘猪︶ㄣ 提交于 2020-01-04 02:40:15
问题 If a NSTextView contains the following: SELECT someTable.someColumn FROM someTable And a user double-clicks someTable.someColumn , the entire thing gets selected (both sides of the period). In this specific case (a query editor), it would make more sense for either the someTable or the someColumn to be selected. I've tried looking around to see if I can figure out a way to customize the selection, but I have been unable to so far. At the moment what I'm thinking of doing is subclassing

How to have a NSTextView with a different font size just for printing?

我的未来我决定 提交于 2020-01-03 01:23:08
问题 I have a NSTextview that only shows good when the text is set to at least 16 in size, but that is too big for printing. How to have a NSTextView with a different font size just for printing ? I have digged into NSPrintInfo but got no result so far. Thanks 回答1: Here's an example: // Create another text view just for printing var printTextView = NSTextView(frame: NSMakeRect(0, 0, 528, 688)) // A4 // Add a modified version of your attributed string to the view printTextView.textStorage!

Font issue with layer backed NSTextView

旧时模样 提交于 2020-01-02 19:32:41
问题 I have a small problem with the nstextview , when I send [textView setWantsLayer:YES] , the font in the textView become blurred, anybody know why is it? [[textView enclosingScrollView] setDrawsBackground:NO]; [textView setDrawsBackground:NO]; [textView setWantsLayer:YES]` 回答1: The problem here is likely with aliasing the text because the background color is transparent, thus causing it to alias against a transparent background, which is going to look pretty bad. Generally, I've found that I