File tree Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -187,12 +187,30 @@ class StandardTableViewCell: NSTableCellView {
187
187
}
188
188
189
189
class SpecialSelectTextField : NSTextField {
190
- // override func becomeFirstResponder() -> Bool {
191
- // TODO: Set text range
192
- // this is the code to get the text range, however I cannot find a way to select it :(
193
- // NSRange(location: 0, length: stringValue.distance(from: stringValue.startIndex,
194
- // to: stringValue.lastIndex(of: ".") ?? stringValue.endIndex))
195
- // return true
196
- // }
190
+ override func becomeFirstResponder( ) -> Bool {
191
+ let range = NSRange (
192
+ location: 0 ,
193
+ length: stringValue. distance (
194
+ from: stringValue. startIndex,
195
+ to: stringValue. lastIndex ( of: " . " ) ?? stringValue. endIndex
196
+ )
197
+ )
198
+ selectText ( self )
199
+ let editor = currentEditor ( )
200
+ editor? . selectedRange = range
201
+ return true
202
+ }
203
+
204
+ override func textDidBeginEditing( _ notification: Notification ) {
205
+ super. textDidBeginEditing ( notification)
206
+ wantsLayer = true
207
+ layer? . backgroundColor = NSColor . textBackgroundColor. cgColor
208
+ }
209
+
210
+ override func textDidEndEditing( _ notification: Notification ) {
211
+ super. textDidEndEditing ( notification)
212
+ wantsLayer = false
213
+ layer? . backgroundColor = nil
214
+ }
197
215
}
198
216
}
You can’t perform that action at this time.
0 commit comments