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

Increase the font size of a NSTextView

I'm trying to create an input text box where the user clicks (point is an NSPoint where the user clicked). Right now I have it working, but the input box that's being displayed is too small. I'd like to have it fill up the outer view (showed in…
James
  • 1,689
  • 3
  • 17
  • 21
7
votes
1 answer

Saving and restoring NSTextView's position

I want to be able to save the current text and visible region of an NSTextView and restore it. Using visibleRect and scrollRectToVisible: seems to deliver inconsistent results. If I just do: - (void)restorePosition { NSRect r = [self.textView…
Matt
  • 385
  • 3
  • 8
7
votes
3 answers

Is NSTextView's insertText: *really* not suitable for programmatic modification of text?

I've written an NSTextView subclass that does frequent programmatic modification of the text within itself (kinda like an IDE's code formatting - auto-insertion of close braces, for example). My initial implementation of this used NSTextView's…
zpasternack
  • 17,838
  • 2
  • 63
  • 81
7
votes
2 answers

Sequential selection among multiple NSTextViews

I have a bunch of NSTextViews that I would like to share a single selection. I basically want this to behave like selecting text on a web page, where there are multiple text views but you can drag to sequentially select text among them. I found this…
indragie
  • 18,002
  • 16
  • 95
  • 164
7
votes
2 answers

NSpoint from NSTextView insertion point

I have an NSTextView and require the coordinates of the insertion point to display a view there upon user interaction. There is a function to get the character index from an NSPoint. I am wondering if there is any easy way to do the…
chaimp
  • 16,897
  • 16
  • 53
  • 86
7
votes
1 answer

CALayer, NSTextView and scaling

In my app I want to provide text scaling in layer backed NSTextView like Apple's TextEdit. I use analogue of it's ScalingScrollView. Also I need to create some CALayer overlays on self.window.contentView. All is ok until I make…
Akki
  • 1,487
  • 14
  • 25
7
votes
2 answers

NSTextView scrolling line by line

When moving from line to line in a textview with "up" and "down" keys, it exhibits this scrolling behavior - when the cursor is at the very top and I hit "up" (and vice versa), it scrolls the document half page up, that is, the current line is now…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
6
votes
1 answer

NSTextAttachmentCell is a mile high

I'm editing a subset of HTML in an NSTextView[1] and I want to simulate an
tag. I've figured out that the way to do it is with NSTextAttachment and a custom NSTextAttachmentCell, and have the code all written to insert the attachment and cell. …
Becca Royal-Gordon
  • 17,541
  • 7
  • 56
  • 91
6
votes
6 answers

Deselect text in an NSTextView programmatically?

I am using the following code to deselect an NSTextView, as suggested here. Unfortunately, nothing at all happens. I have tried what I know to debug it, but everything seems to be working correctly, but it doesn't affect the NSTextView. The code: //…
Justin
  • 2,122
  • 3
  • 27
  • 47
6
votes
1 answer

Custom Data Detectors in NSTextView (similar to the recognition of dates)

Is there a way to implement custom data detectors in NSTextView (like the one that recognizes dates or telephone numbers)? I think there is an API Reference, but the whole process is not documented. Is there anything that can help me understand…
Donovan
  • 6,002
  • 5
  • 41
  • 55
6
votes
0 answers

Checkbox in NSTextList

How do I get checkbox as a marker in an NSTextList? I want the user to be able to click the checkbox on which it will change to another symbol (a check marker or a thumbs up or the checkbox with a cross inside...). How can I do that? I played a…
DaPhil
  • 1,509
  • 4
  • 25
  • 47
6
votes
3 answers

Truncate NSTextView?

I tried using defaultParagraphStyle, but I can't seem to get a NSTextView (programmatically added) to truncate text with an ellipsis (...). I am setting the frame during the initWithFrame (150, 20) and I also set the maxSize (150,20). However, text…
Andrew M
  • 4,208
  • 11
  • 42
  • 67
6
votes
1 answer

NSRulerView how to correctly align line numbers with main text

I am using a NSRulerView in MacOS in order to display line numbers next to a NSTextView. Both views share the same font and the same font size, however while in NSTextView string rendering is automatically managed, in the NSRulerView I need to…
Marco
  • 783
  • 5
  • 21
6
votes
0 answers

NSTextStorage easily / background attribute change

I'm finishing a nice app with a relatively small text editor. During implementation of the syntax highlight I found myself in need to change foreground colour attribute of recognized tokens. I noticed that there is a property of NSTextStorage: var…
Ivaylo Nikolov
  • 501
  • 4
  • 13
6
votes
1 answer

Swift - Does controlTextDidChange Work With NSTextView?

I have one text field and one textView. The controlTextDidChange method responds to a text field change. But it doesn't respond to a textview change. class AppDelegate: NSObject,NSApplicationDelegate,NSTextFieldDelegate,NSTextViewDelegate { …
El Tomato
  • 6,479
  • 6
  • 46
  • 75