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

Improve textfield behavior in Project Navigator #1291

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,30 @@ class StandardTableViewCell: NSTableCellView {
}

class SpecialSelectTextField: NSTextField {
// override func becomeFirstResponder() -> Bool {
// TODO: Set text range
// this is the code to get the text range, however I cannot find a way to select it :(
// NSRange(location: 0, length: stringValue.distance(from: stringValue.startIndex,
// to: stringValue.lastIndex(of: ".") ?? stringValue.endIndex))
// return true
// }
override func becomeFirstResponder() -> Bool {
let range = NSRange(
location: 0,
length: stringValue.distance(
from: stringValue.startIndex,
to: stringValue.lastIndex(of: ".") ?? stringValue.endIndex
)
)
selectText(self)
let editor = currentEditor()
editor?.selectedRange = range
return true
}

override func textDidBeginEditing(_ notification: Notification) {
super.textDidBeginEditing(notification)
wantsLayer = true
layer?.backgroundColor = NSColor.textBackgroundColor.cgColor
}

override func textDidEndEditing(_ notification: Notification) {
super.textDidEndEditing(notification)
wantsLayer = false
layer?.backgroundColor = nil
}
}
}