Posts

Post not yet marked as solved
1 Replies
362 Views
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.
Posted
by zcius.
Last updated
.
Post not yet marked as solved
1 Replies
446 Views
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   } }
Posted
by zcius.
Last updated
.
Post not yet marked as solved
3 Replies
1.1k Views
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?
Posted
by zcius.
Last updated
.
Post not yet marked as solved
1 Replies
692 Views
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 ?
Posted
by zcius.
Last updated
.