Questions tagged [nstextview]

NSTextView is the front-end class to MacOS's Application Kit text system. It draws the text managed by the back-end components and handles user events to select and modify its text. While NSTextView is a subclass of NSText—which declares the most general Cocoa interface to the text system—NSTextView adds major features beyond the capabilities of NSText.

Text views are user interface objects instantiated from the NSTextView class. Text views typically display multiple lines of text laid out in paragraphs with all the characteristics of sophisticated typesetting. A text view is the main user interface to the Cocoa text-editing system. It handles user events to provide text entry and modification, and to display any font, including those of non-English languages, with arbitrary colors, styles, and other attributes.

The Cocoa text system supports text views with many other underlying objects providing text storage, layout, font and attribute manipulation, spell checking, undo and redo, copy and paste, drag and drop, saving of text to files, and other features. NSTextView is a subclass of NSText, which is a separate class for historical reasons. You don’t instantiate NSText, although it declares many of the methods you use with NSTextView. When you put an NSTextView object in an NSWindow object, you have a full-featured text editor whose capabilities are provided “for free” by the Cocoa text system.

871 questions
13
votes
4 answers

How to uniformly scale rich text in an NSTextView?

Context: I have a normal Document-based Cocoa Mac OS X application which uses an NSTextView for rich text input. The user may edit the font family, point size and colors of the text in the NSTextView. Base SDK: 10.7 Deployment Target:…
Todd Ditchendorf
  • 11,217
  • 14
  • 69
  • 123
12
votes
2 answers

Hide Markdown Characters with NSLayoutManager in Swift

I am working on a rich text editor in a Mac app that uses Markdown syntax. I use NSTextStorage to watch for matches in Markdown syntax, then apply styles to the NSAttributedString in real time like this: At this point, I'm already in way over my…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
12
votes
5 answers

How to change only font size for the whole styled text in NSTextView

I need to set a text size (for example to 42) of the selected rich text which uses multiple fonts. I imagine I can check attributes of each group of characters, modify the font size and set attributes back, but looking at the floating Font panel it…
Indoor
  • 541
  • 4
  • 16
12
votes
3 answers

How can I get the selection direction of an NSTextView?

I'm trying to get the direction of the selected ranges in an NSTextView. In other words, whether the selected ranges change their location or length when you use shift+leftarrow and shift+rightarrow. My first though was that selectionAffinity…
zakdances
  • 22,285
  • 32
  • 102
  • 173
12
votes
2 answers

How to find caret position in an NSTextView?

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?
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
12
votes
2 answers

NSTextView with tokens

How can I add tokens, like NSTokenField, to a NStextView?
gcstr
  • 1,466
  • 1
  • 21
  • 45
12
votes
3 answers

Completely disable NSTextView spell checking

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…
David Beck
  • 10,099
  • 5
  • 51
  • 88
11
votes
2 answers

NSBackgroundColorAttributeName in textView doesn't respect range if highlighted word is first of a line

I'm implementing a "search in chat" feature and I want the searched word to be highlighted in messages. The problem, as described in title, is that if the word is the first of a line (long messages are clearly multi-line), the entire line is…
11
votes
3 answers

Subdivide a text view's attributed string into (referable) sections

I'm trying to implement a very simple text editor that should work both with NSTextView on macOS and UITextView on iOS. This text editor has a toolbar button "Section Break" that inserts a new section at the current cursor position every time it is…
Mischa
  • 15,816
  • 8
  • 59
  • 117
11
votes
3 answers

How to set up an NSTextView programmatically with explicit NSLayoutManager, NSTextStorage, NSTextContainer?

Following the apple documentation I am trying to set up a simple NSTextView via its two constructor methods. I am placing the below code inside the viewDidAppear method of the view controller of the content view. textView is an instance of…
Sam
  • 2,745
  • 3
  • 20
  • 42
11
votes
2 answers

Programmatically set up NSTextView inside NSScrollView

I'm trying to set up an NSTextView in an NSScrollView programmatically and am having trouble. Specifically, I can't scroll the text view; the scroll view seems to think "this is all there is". When you try to scroll down to see the rest of the…
Kalle
  • 13,186
  • 7
  • 61
  • 76
11
votes
2 answers

Rendering differences between NSTextField and NSTextView on a black background

I'm trying to draw text onto a black background and I'm seeing some differences in the way the text is rendered. Here's my code: NSTextView * textView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 500.0f, 50.0f)]; [textView…
Aaron
  • 111
  • 4
11
votes
1 answer

Proper way to replace NSTextStorage in NSTextView?

I am making some text viewer app. Currently I need very frequent and precise line handling ability, so I want to subclass NSTextStorage class. But I couldn't find any method to set a new text storage to NSTextView. The only method I could find was…
eonil
  • 83,476
  • 81
  • 317
  • 516
11
votes
3 answers

NSTextField width and autolayout

I am trying to create an NSTextField programmatically. I want to use this NSTextField with auto layout, so its width will be defined automatically to display the entire line (there is only one line of text). The problem is that…
Yoav
  • 5,962
  • 5
  • 39
  • 61
10
votes
3 answers

How to implement undo/redo with programatic change of the textValue of a NSTextView?

I created a simple demo app with a NSTextView and a button, the provided a NSTextViewDelegate to the textView and added an action: - (IBAction)actionButtonClicked:(id)sender { NSString *oldText = [[[self.textView textStorage] string] copy]; …
user808667
  • 333
  • 3
  • 11
1 2
3
58 59