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
10
votes
1 answer

Completion in NSTextView

I am looking for a way (or code) to have a completion list close to the one of xcode Do you know how to achieve this? Thanks and regards,
AP.
  • 5,205
  • 7
  • 50
  • 94
10
votes
1 answer

Faking an NSTextField using an NSTextView to get nice coloring?

Trying to change the selected text background color for an NSTextField (we have a dark UI, and selected text background is almost the same as the text itself), but only NSTextView seems to allow us to change this. So we're trying to fake an…
hasvn
  • 1,054
  • 1
  • 11
  • 15
9
votes
2 answers

How can you intercept pasting into a NSTextView to remove unsupported formatting?

I'm trying to create a simple NSTextView-based window for simple WYSIWYG editing. However, I only want to allow certain types of formatting (e.g. Bold, Italic, Underline and a single heading type but no colors or different fonts.) The issue is if I…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
9
votes
3 answers

Automatic Link Detection not working in NSTextView after programmatically setting text

I have an NSTextView with automatic link detection enabled. When I set the text programmatically [myTextView setString:@"http://google.com"] it doesn't automatically show the link. If I type anything into the text view it will add the link. I want…
Randall
  • 14,691
  • 7
  • 40
  • 60
9
votes
1 answer

Saving and pasting an attributed string with a custom NSTextBlock

I am trying to create a custom NSTextBlock, much like the one Apple did at WWDC 18 (23 mins in). Full demo project here. Okay, so it works great when I'm editing and marking a paragraph with my paragraph style that has the text block attached.…
9
votes
4 answers

How do I limit NSTextView to 2 lines?

I'm trying to specify the number of lines for NSTextView. My designer is requesting 2 lines of text max. I've tried NSMutableParagraph style to add the ellipses truncation that I want, but with NSMutableParagraph I can only get NSTextView with 1…
9
votes
2 answers

Setting the Line Height/ Line Spacing in an NSTextView

How would I set the Line Height or Line Spacing in an NSTextView (i.e. how tall each line is, or how much space is between each line)?
Joshua
  • 15,200
  • 21
  • 100
  • 172
9
votes
2 answers

bind:toObject:withKeyPath:options: is one-way binding?

I have two windows: Window A is loaded from NIB; and Window B is created programmatically. Both windows have a NStextView: the attributedString of the textview in Window A is bound to the the property text of a model using IB; while the…
Jensen
  • 1,653
  • 4
  • 26
  • 42
9
votes
2 answers

Get & Highlight Current Word in an NSTextView

OK, so this is what I want : We have an NSTextView Get "current" word (as an NSRange?), at cursor position (how could this be determined?) Highlight it (change its attributes) I'm not sure how to go about this : I mean my main concern is getting…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
8
votes
1 answer

How do I use SPACE instead of TAB in NSTextView

I just know how to modify the tab width in NSTextView NSMutableParagraphStyle *paragraphStyle = [[self defaultParagraphStyle] mutableCopy]; [paragraphStyle setTabStops:[NSArray array]]; [paragraphStyle setDefaultTabInterval: tabWidth]; But, is…
joyqi
  • 123
  • 2
  • 7
8
votes
1 answer

How to draw focus ring around NSBox on focus of child NSTextView in objective-c

I have one NSTextView within NSBox. I want to draw focus ring aroung NSBox whenever NSTextView got focus and remove focus ring as soon as NSTextView lost focus. Thanks,
AmitSri
  • 1,209
  • 1
  • 20
  • 48
8
votes
1 answer

How to programmatically add bullet list to NSTextView

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…
GregoryM
  • 547
  • 5
  • 23
8
votes
1 answer

NSTextField autocompletion delegate method not called

I implemented the following delegate method for NSTextField to add autocompletion support: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words …
indragie
  • 18,002
  • 16
  • 95
  • 164
8
votes
1 answer

How Can I Know When NSTextView Loses Focus?

I want to clear the selection of NSTextView after it loses focus. How can I achieve that? Thanks in advance! Kai.
nonamelive
  • 6,510
  • 8
  • 40
  • 47
8
votes
1 answer

NSTextView not selectable within text container inset

I'm setting the textContainerInset of an NSTextView to some values. self.textView.textContainerInset = NSMakeSize(10, 10); How do you make the text view selectable in the inset area? The text cursor appears but nothing happens if I try to select…
Berry Blue
  • 15,330
  • 18
  • 62
  • 113