Can I prevent text highlight when I hit “return” keystroke on a NSTextField?

此生再无相见时 提交于 2019-12-12 22:24:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!