Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger VC: Enter now inserts a newline in the script body field #59

Merged
merged 1 commit into from
May 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Buildasaur/TriggerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TriggerViewController: SetupViewController, NSComboBoxDelegate {
override func viewDidLoad() {
super.viewDidLoad()

self.bodyTextField.delegate = self
self.typeComboBox.removeAllItems()
self.typeComboBox.addItemsWithObjectValues(self.allKinds().map({ $0.toString() }))
self.typeComboBox.delegate = self
Expand Down Expand Up @@ -220,6 +221,33 @@ class TriggerViewController: SetupViewController, NSComboBoxDelegate {
func comboBoxWillDismiss(notification: NSNotification) {
self.reloadUI()
}
}

extension TriggerViewController: NSTextFieldDelegate {

//Taken from https://developer.apple.com/library/mac/qa/qa1454/_index.html
func control(control: NSControl, textView: NSTextView, doCommandBySelector commandSelector: Selector) -> Bool {

let result: Bool
switch commandSelector {

case Selector("insertNewline:"):
// new line action:
// always insert a line-break character and don’t cause the receiver to end editing
textView.insertNewlineIgnoringFieldEditor(self)
result = true

case Selector("insertTab:"):
// tab action:
// always insert a tab character and don’t cause the receiver to end editing
textView.insertTabIgnoringFieldEditor(self)
result = true

default:
result = false
}

return result
}
}