nstextview

How to find caret position in an NSTextView?

a 夏天 提交于 2019-11-28 21:35:15
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? NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location; For Swift 4 let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location 来源: https://stackoverflow.com/questions/1701129/how-to-find-caret-position-in-an-nstextview

Using Autolayout with expanding NSTextViews

*爱你&永不变心* 提交于 2019-11-28 16:20:48
问题 My app consists of an NSScrollView whose document view contains a number of vertically stacked NSTextViews — each of which resizes in the vertical direction as text is added. Currently, this is all managed in code. The NSTextViews resize automatically, but I observe their resizing with an NSViewFrameDidChangeNotification , recalc all their origins so that they don't overlap, and resize their superview (the scroll view's document view) so that they all fit and can be scrolled to. This seems as

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

和自甴很熟 提交于 2019-11-28 03:09:29
I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line height of this font, if I would use it in an NSTextView is 111.0. NSLayoutManager *lm = [[NSLayoutManager alloc] init]; NSLog(@"%f", [lm defaultLineHeightForFont:font]); // this is 111.0 Now, if I do the same thing with Core Text, the result is 110.4 (assuming you can calculate the line height by adding the ascent, descent and leading). CTFontRef

Completely disable NSTextView spell checking

不想你离开。 提交于 2019-11-27 23:44:38
问题 How can I disable spell checking for an NSTextView? In particular, the red lines that are automatically drawn. I know about the "Continuous Spell Checking" option in Xcode, and every option I have found in the documentation related to spell checking doesn't seem to take the red lines away. 回答1: Select NSTextView (doubleClick in IB on it because NSTextView is in NSScrollView by default or select it in Document Outline ) and go to Attributes Inspector -> Linguistics -> and uncheck Continous

Scrolling NSTextView to bottom

不想你离开。 提交于 2019-11-27 16:22:06
问题 I'm making a little server app for OS X and I'm using an NSTextView to log some info about connected clients. Whenever I need to log something I'm appending the new message to the text of the NSTextView this way: - (void)logMessage:(NSString *)message { if (message) { self.textView.string = [self.textView.string stringByAppendingFormat:@"%@\n",message]; } } After this I'd like the NSTextField (or maybe I should say the NSClipView that contains it) to scroll down to show the last line of its

NSTextView insert image in between text

﹥>﹥吖頭↗ 提交于 2019-11-27 13:23:44
问题 Is it possible to insert an image (not a background image) into an NSTextView ? Something like: Hi :) How are you? and it should display a "smiley" image. I have an NSTextView and an NSImage . 回答1: Insert NSImage into NSTextView: NSImage * pic = [[NSImage alloc] initWithContentsOfFile:@"/Users/Anne/Desktop/Sample.png"]; NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:pic]; NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; [attachment

How to get height for NSAttributedString at a fixed width

无人久伴 提交于 2019-11-27 09:50:26
问题 I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size , but the results are useless (for this purpose), as they'll give whatever width the string desires. Calling - (void)drawWithRect:(NSRect)rect options:(NSStringDrawingOptions)options with a rect shaped to the width I want and NSStringDrawingUsesLineFragmentOrigin in the options, exactly as I'm using in

Real time NSTask output to NSTextView with Swift

一曲冷凌霜 提交于 2019-11-26 15:29:59
I'm using an NSTask to run rsync, and I'd like the status to show up in the text view of a scroll view inside a window. Right now I have this: let pipe = NSPipe() task2.standardOutput = pipe task2.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output: String = NSString(data: data, encoding: NSASCIIStringEncoding)! as String textView.string = output And that get's me the some of the statistics about the transfer, but I'd like to get the output in real time, like what get's printed out when I run the app in Xcode, and put it into the text view. Is there a way to do this?

Real time NSTask output to NSTextView with Swift

亡梦爱人 提交于 2019-11-26 03:59:02
问题 I\'m using an NSTask to run rsync, and I\'d like the status to show up in the text view of a scroll view inside a window. Right now I have this: let pipe = NSPipe() task2.standardOutput = pipe task2.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output: String = NSString(data: data, encoding: NSASCIIStringEncoding)! as String textView.string = output And that get\'s me the some of the statistics about the transfer, but I\'d like to get the output in real time, like