问题
Before I hit "return" keystroke:
After I hit "return" keystroke:
I don't want that highlight, just want to keep it unchanged. How can I do that?
Here is the code snippet for this text field:
let searchField = NSTextField()
searchField.isBezeled = false
searchField.drawsBackground = false
searchField.textColor = .white
searchField.focusRingType = .none
searchField.usesSingleLineMode = true
searchField.cell?.sendsActionOnEndEditing = false
searchField.target = self
searchField.action = #selector(searchAction)
Edit: Seems like it's just highlight but not a selection,because
let textEditor = window?.fieldEditor(true, for: searchField)
textEditor.selectedRange.length == 0 //length is 0
来源:https://stackoverflow.com/questions/53977719/can-i-prevent-text-highlight-when-i-hit-return-keystroke-on-a-nstextfield