having the same issue on swift 6 macos 15.1 xcode 16.0 beta4
Post
Replies
Boosts
Views
Activity
figure it out
public func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool {
if replacementString == "K" {
return false
}
return true
}
after a system update, it works, closed
Same issue, haven't found any answer yet.
I found a similar case here How can I remove Textfield focus when I press return or click outside Textfield? (SwiftUI, MacOS) - https://stackoverflow.com/questions/58987542/how-can-i-remove-textfield-focus-when-i-press-return-or-click-outside-textfield,with the following code
swift
func onCommit() - Void {
DispatchQueue.main.async {
NSApp.keyWindow?.makeFirstResponder(nil)
}
}
It's almost what I want, except that, after I press return key, I can see the selection flash and quickly disappear.