user158058
user158058

Reputation:

Auto-Indentation in a NSTextView

I'm working on a simple code editor in Cocoa. I have a text view, and I want it so that when the user hits return, the new line is indented the same as the previous line (like in Xcode or any other code editor).

My problem is that I can't figure out how to either intercept when the return/enter key is pressed or when a new line is created in the text view. What would be the easiest way to do this?

Upvotes: 1

Views: 1114

Answers (1)

Chuck
Chuck

Reputation: 237080

You can override insertNewline: in the NSTextView if that's what you have. You can also implement the delegate method textView:doCommandBySelector:, which will be called with the insertNewline: selector as an argument when the user presses return.

Upvotes: 4

Related Questions