You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project, I experienced a crash due to multiple constraint updates in a single pass (or something like that - it's been a couple days and I'm going off memory) when attempting to create an STTextView outside a scroll view.
In commit 639400ea6, I reproduced the issue with the following changes to ViewController.swift in the TextEdit sample:
// Created by Marcin Krzyzanowski// https://github.com/krzyzanowskim/STTextView/blob/main/LICENSE.md
import AppKit
import STTextView
import SwiftUI
// import DummyPluginfinalclassViewController:NSViewController{privatevartextView:STTextView!privatevarcompletions:[Completion.Item]=[]overridefunc viewDidLoad(){
super.viewDidLoad()// let scrollView = STTextView.scrollableTextView()// textView = scrollView.documentView as? STTextView
textView =STTextView()// scrollView.translatesAutoresizingMaskIntoConstraints = false// scrollView.hasVerticalScroller = true// scrollView.drawsBackground = trueletparagraph=NSParagraphStyle.default.mutableCopy()as!NSMutableParagraphStyle
paragraph.lineHeightMultiple = 1.2
textView.typingAttributes[.paragraphStyle]= paragraph
// textView.font = NSFont.monospacedSystemFont(ofSize: 0, weight: .regular)
textView.string =try!String(contentsOf:Bundle.main.url(forResource:"content", withExtension:"txt")!)
textView.isHorizontallyResizable = false // wrap
textView.highlightSelectedLine = true
textView.isIncrementalSearchingEnabled = true
textView.showsInvisibleCharacters = false
textView.delegate =self
textView.isEditable = false
textView.isSelectable = true
// Plugins// textView.addPlugin(DummyPlugin())// Line numbers// let rulerView = STLineNumberRulerView(textView: textView)// rulerView.font = NSFont.monospacedSystemFont(ofSize: 0, weight: .regular)// rulerView.allowsMarkers = true// rulerView.highlightSelectedLine = true// scrollView.verticalRulerView = rulerView// scrollView.rulersVisible = true// view.addSubview(scrollView)// NSLayoutConstraint.activate([// scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),// scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),// scrollView.topAnchor.constraint(equalTo: view.topAnchor),// scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor)// ])
textView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(textView)NSLayoutConstraint.activate([
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
textView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
textView.topAnchor.constraint(equalTo: view.topAnchor),
textView.bottomAnchor.constraint(equalTo: view.bottomAnchor)])// Add attributes// add link to occurences of STTextViewdo{letstr= textView.string
varcurrentRange= str.startIndex..<str.endIndex
while let ocurrenceRange = str.range(of:"STTextView", range: currentRange){
textView.addAttributes([.link:URL(string:"https://swift.best")! asNSURL], range:NSRange(ocurrenceRange, in: str))
currentRange = ocurrenceRange.upperBound..<currentRange.upperBound
}}do{letstr= textView.string
varcurrentRange= str.startIndex..<str.endIndex
while let ocurrenceRange = str.range(of:"vim", range: currentRange){
textView.addAttributes([.cursor:NSCursor.operationNotAllowed], range:NSRange(ocurrenceRange, in: str))
currentRange = ocurrenceRange.upperBound..<currentRange.upperBound
}}// Insert attachment image using NSTextAttachmentCell//// do {// let attachment = NSTextAttachment()// let img = NSImage(systemSymbolName: "figure.walk", accessibilityDescription: nil)// let cell = NSTextAttachmentCell(imageCell: img)// attachment.attachmentCell = cell// let attachmentString = NSAttributedString(attachment: attachment)// textView.insertText(attachmentString, replacementRange: NSRange(location: 20, length: 0))// }//// Insert attachment image using NSTextAttachmentViewProviderdo{letattachment=MyTextAttachment()letattachmentString=NSAttributedString(attachment: attachment)
textView.insertText(attachmentString, replacementRange:NSRange(location:30, length:0))}// Emphasize first line
textView.addAttributes([.foregroundColor:NSColor.controlAccentColor,.font:NSFont.monospacedSystemFont(ofSize:NSFont.systemFontSize * 1.2, weight:.bold)],
range:NSRange(textView.string.linesRanges().first!, in: textView.string))updateCompletionsInBackground()}// ... the rest is unchanged
I was hoping to find time to contribute back to the project and dig into this deeper, but it's looking grim that I'll be able to do so. Hopefully someone will be able to find a fix!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In my project, I experienced a crash due to multiple constraint updates in a single pass (or something like that - it's been a couple days and I'm going off memory) when attempting to create an STTextView outside a scroll view.
In commit 639400ea6, I reproduced the issue with the following changes to
ViewController.swift
in the TextEdit sample:I was hoping to find time to contribute back to the project and dig into this deeper, but it's looking grim that I'll be able to do so. Hopefully someone will be able to find a fix!
Beta Was this translation helpful? Give feedback.
All reactions