nstextview

NSTextView making bold text using an array

心已入冬 提交于 2019-12-11 09:42:45
问题 I have an array which has the following structure: ( [0] = ( [0] = @"Title string" [1] = @"Some content string" ) [1] = ( [0] = @"Title string" [1] = @"Some content string" ) [2] = ( [0] = @"Title string" [1] = @"Some content string" ) ... ) and so on and so fourth to a variating amount of reoccurrence. My goal is to try and merge it all into one single string to display in an NSTextField, and make every title string bold. So the code above would look something like this if it were outputted.

NSTextView cursor doesn't appear when typing text on macOS 10.14

南笙酒味 提交于 2019-12-11 07:57:08
问题 I'm observing a strange issue on macOS 10.12 Mojave with NSTextView. . I'm changing the textStorage attributes in didChangeText() like this : self.textStorage?.beginEditing() ARTokenManager.getToken(text: text, language: language) { (tokens) in // This line reset the attributes // If I remove it, the cursor appear properly // But the attributes are conserved self.textStorage?.setAttributes([NSAttributedString.Key.font: self.font!, NSAttributedString.Key.foregroundColor: self.defaultTextColor]

How to use NSTextFinder programmatically?

我与影子孤独终老i 提交于 2019-12-11 04:54:47
问题 I'd like to do a "find" operation in an NSTextView without using the built-in find bar. How can I programmatically set a search string and have the results highlighted inside the text view? This is for macOS 10.12 and higher. FWIW, this is not a duplicate of this question: NSTextFinder set search string and clear visual feedback programatically That question is about programmatically controlling the find bar UI, either clearing previous find results or populating the find bar search field.

How to set first responder for NSTextView in Swift?

大憨熊 提交于 2019-12-10 23:52:48
问题 Edit: in a macOS project I have a simple ViewController which I display as popover on a status item menu app. I change the text of the view text with a NSTableView, depending of which item is clicked. The code I use is similar to this one: mainTextField.insertText(newStr, replacementRange: theRange) (I use insertText for the purpose to have the change recorded in undo manager) Then I highlight the text: // create the new NSRange let range = NSRange(location: startRange, length: newStrLength)

Set the cursor to a pointing hand over a text view

核能气质少年 提交于 2019-12-10 17:20:54
问题 Is there a way to set the cursor to a pointing hand over a text view without subclassing NSTextView? I read a lot about NSTrackingAreas, tested a lot of examples, set different tracking options and implemented different methods, but the cursor still remains an I-Beam. I have read that it is an AppKit automatic feature, so how can I prevent this? Thank you! 回答1: I had to subclass. After a couple of hours to test a lot of methods and options, this finally worked : @implementation ATTextView -

How to change the mouse style of NSView and NSButton on NSTextView

主宰稳场 提交于 2019-12-10 15:15:21
问题 There is a NSView on top of NSTextView, and the range of NSTextview is larger than the NSView range. NSView has some of the above NSButton and so on, work very well, but the mouse style makes me a bit puzzled. I think that when the mouse moves to NSView, it has been a arrow style, but not, it always displays the iBeam style. Because it's on the NSTextView, so when my mouse moves to NSView, it shows the iBeam style. I change mouse NSCursor.arrow.set in real time by override func mouseMoved

NSTextView selection highlights all characters even paragraph indents

你说的曾经没有我的故事 提交于 2019-12-10 10:08:20
问题 Can't find any clue how to manage this. By default, NSTextView selection highlights the whole size of its text container. It ignores line spacing, head or tail indents etc. But in Pages app selection doesn't highlight those ancillary parts, it highlight characters ONLY. And it highlights all the height of the line even if text container's height is smaller (paragraph spacing before and after). I want to implement that behavior but can't understand where to begin. I've searched here, I've

How to get the selected line range of NSTextView?

无人久伴 提交于 2019-12-10 09:26:33
问题 How to get the selected line range of NSTextView ? 回答1: 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

How do I make a Cocoa NSTextView grow as the user types into it?

故事扮演 提交于 2019-12-10 04:21:34
问题 For a Cocoa application I am writing, I would like to support a panel to the right of the main document content where users can add notes for the currently selected document content. (If you are familiar with Microsoft Word or Scrivener, this feature is similar to the comment feature in those applications.) Scrivener does a nice job of starting with a text field sized to fit the default text, and then growing it taller as the user types into it. I'd like to implement the same behavior for my

What's the equivalent “sizeWithFont: ” method for the Mac?

眉间皱痕 提交于 2019-12-10 03:43:51
问题 I'm familiar with sizeWithFont: for the iPhone. Now I'm trying to build an app for the Mac and need something like that, but I don't know how to do it :/ Here's why I need it: I've got a panel that displays some text, and I want to size it so that it just fits the content (a NSTextView ). How would you do it? 回答1: Take a look at NSString's sizeWithAttributes: . You'll have to create a dictionary of attributes; take a look at Apple's documentation for that. 来源: https://stackoverflow.com