Post

Replies

Boosts

Views

Activity

Textkit2 NSTextView get cursor coordinate
I need to render some view at cursor position, how can I get the current coordinate of cursor? var location = NSRange(location: textView.selectedRange().location, length: 0) // the following is not available textLayoutManager.boundingRect(forGlyphRange: location, in: textContainer) can we use Textkit2 in production? I think there are lots of methods missing in NSTextLayoutManager while available in NSLayoutManager.
1
0
1.2k
Oct ’21
Textkit2 NSTextView textContentStorage is nil
I can't get NSTextView to work in textkit2 with the following code, textView.textContentStorage , textContentStorage.textStorage is both nil. does anyone have a working example? hope there is a Frameworks Engineer help me out, appreciate so much. import AppKit open class MyEditor: NSView {   let textView: NSTextView   let textLayoutManager: NSTextLayoutManager   let textContentStorage: NSTextContentStorage   public init() {     textLayoutManager = NSTextLayoutManager()     textContentStorage = NSTextContentStorage()           let textContainer = NSTextContainer(size: NSSize(width: 200, height: 0.0))     textContainer.widthTracksTextView = true     textContainer.heightTracksTextView = true           textLayoutManager.textContainer = textContainer     textContentStorage.addTextLayoutManager(textLayoutManager)           textView = NSTextView(frame: .zero, textContainer: textContainer)               super.init(frame: .zero)           addSubview(textView)   }       public func setAttributedString(_ attrString: NSAttributedString) {     print(textView.textContentStorage) // always nil     textContentStorage.textStorage?.setAttributedString(attrString)   }       public required init?(coder: NSCoder) {     return nil   } }
1
0
975
Jul ’21
SwiftUI - List inside horizontal ScrollView on MacOS, unable to scroll horizontally
I'm trying to create a horizontal ScrollView, inside which there are many Lists that can scroll vertically. like MacOS Finder app The problem is, horizontal scroll is not happening if mouse scroll is triggered inside List. My guess is that scroll event is captured by List, ScrollView has no chance to handle. ScrollView(.horizontal) { List List List ... } Does any has any workaround?
3
0
1.8k
Oct ’20
SwiftUI TextField on macos hit `return` key won't resign responder, instead select all text?
Swift private struct MyView: View {      @State var text: String = "textfield value."       func onEditingChanged (isEditing: Bool) - Void {     print("changed \(isEditing)")   }       func onCommit() - Void {     print("commited")     NSApplication.shared.sendAction(#selector(NSResponder.resignFirstResponder), to:nil, from:nil)   }       var body: some View {     HStack {       TextField("x", text: $text, onEditingChanged: onEditingChanged, onCommit: onCommit)         .textFieldStyle(PlainTextFieldStyle())         .disableAutocorrection(true)     }   } } After I finish entering on TextField and hit return key on my keyborad,I'm expecting the textfield to lose focus. However,it won't, and instead, all text in the textfield is selected? is there some workaround ?
1
0
1.8k
Apr ’21