Skip to content

Commit 851dc79

Browse files
authored
Improve textfield behavior in Project Navigator (#1291)
* feat: exclude file extension when renaming filename * feat: add background layer while editing
1 parent e73b510 commit 851dc79

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

CodeEdit/Features/NavigatorSidebar/OutlineView/StandardTableViewCell.swift

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,30 @@ class StandardTableViewCell: NSTableCellView {
187187
}
188188

189189
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+
}
197215
}
198216
}

0 commit comments

Comments
 (0)