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

Transparent Background for TextEditor in SwiftUI

I am using SwiftUI to build an app for iOS, iPadOS and macOS and I need a TextEditor with a transparent background. This question has been asked before and I found a good answer for iOS/iPadOS (Change background color of TextEditor in SwiftUI), but…
Alex Seifert
  • 113
  • 3
  • 14
5
votes
1 answer

MouseMoved notification in NSTextView produces message "Shared items array is empty"

I am using a custom mouseMove event in NSTextView to set the cursor to a pointer when it's outside the content insets. When it's inside the editable area, I'm calling [super mouseMove]: - (void)mouseMoved:(NSEvent*)event { NSPoint point = [self…
Tritonal
  • 607
  • 4
  • 16
5
votes
1 answer

NSTextView drag text with custom attributes

I am having an issue regarding my NSTextView subclass. My view contains attributed strings with custom attributes, therefore I had to implement the following pasteboard methods to ensure that my custom attributes get copied on to the…
Joseph Williamson
  • 771
  • 1
  • 6
  • 18
5
votes
2 answers

NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) moves selection

I'm trying to implement a syntax-coloring text editor that also does things like insert whitespace at the start of a new line for you, or replace text with text attachments. After perusing the docs again after a previous implementation had issues…
uliwitness
  • 8,532
  • 36
  • 58
5
votes
1 answer

How to set first responder for NSTextView in Swift?

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…
Cue
  • 2,952
  • 3
  • 33
  • 54
5
votes
1 answer

How to change NSCursor globally?

I am developing an application with several windows and views (NSTextView, etc.). I would like to change the cursor globally in my application, so that even if the cursor enters the trackingRect of (for instance) an NSTextView it does not change. Is…
Colas
  • 3,473
  • 4
  • 29
  • 68
5
votes
3 answers

Getting NSTextView to perfectly fit its contents

I have a view that contains a button and a textview. When the button is clicked, the textview's hidden status will change and be shown on the view. Springs and struts have been configured so the textview expands vertically with the view. All this is…
IEb
  • 137
  • 2
  • 7
5
votes
0 answers

Cocoa: NSTextView without NSScrollView

I'm building a chat application with the chat pane as an NSTableView and each message held within a custom cell in a row in that table. I need to make the table row height relative to the message size. After many frustrations with trying to…
SuddenMoustache
  • 883
  • 7
  • 17
5
votes
1 answer

What is equivalent of contentInset property on NSTextView?

I am developing macOS application and want to add NSTextView. I could not find contentInset property on NSTextView. How to set contentInset for NSTextView? Following is iOS code, what is macOS equivalent for the same? UITextView* textView =…
Ganesh Amrule
  • 407
  • 2
  • 12
5
votes
2 answers

Listen for changes to NSTextView with NSTextViewDelegate & textViewDidChange not working

I want a function to fire every time the user makes a change to my NSTextView. I got this to work in an iOS app and am now trying to make it work in an OS X app. I created an outlet for my NSTextView and wrote the following Swift code: import…
user1822824
  • 2,478
  • 6
  • 41
  • 65
5
votes
1 answer

NSTextView: how to disable single clicks but still allow selection for copy-and-paste?

I have NSTextView-based component and I would like to disable single clicks on it, so that its insertion point is not affected by these single clicks, but still to be able to select pieces of text for copy-and-paste work: single clicks do…
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
5
votes
2 answers

NSTextFinder + programmatically changing the text in NSTextView

I have a NSTextView for which I want to use the find bar. The text is selectable, but not editable. I change the text in the text view programatically. This setup can crash when NSTextFinder tries to select the next match after the text was changed.…
Pierre Bernard
  • 3,148
  • 2
  • 23
  • 31
5
votes
1 answer

How to tell NSTextView which side to extend selection on?

If I have an NSTextView which is in this state: How can I tell the textview that if a user presses shift+right, that rather than extending right towards the 'o', it instead de-selects the 'e'? I though this had to do with the affinity, but I have…
Kyle
  • 17,317
  • 32
  • 140
  • 246
5
votes
1 answer

How do I get the line and column number of a character at some index in Text View?

I have a NSTextView in which I have lots of text. How can I get the line and the column number of the character at some index? Lets say, I have this text in the NSTextView: "This is just a\ndummy text\nto show you\nwhat I mean." And I need the…
Dejan Skledar
  • 11,280
  • 7
  • 44
  • 70
5
votes
2 answers

Xcode-style placeholders in an NSTextView

In Xcode, if you type <# Hello, Word #> into the text editor, it automatically gets converted to a pale-blue pill-shaped placeholder, but on disk, the text remains exactly as it was typed. Does anyone know if the same effect is achievable using…
Paul Patterson
  • 6,840
  • 3
  • 42
  • 56