























@@ -444,34 +444,18 @@ private struct ChatComposerTextView: NSViewRepresentable {
444444func makeCoordinator() -> Coordinator { Coordinator(self) }
445445446446func makeNSView(context: Context) -> NSScrollView {
447-let textView = ChatComposerNSTextView()
448- textView.delegate = context.coordinator
449- textView.drawsBackground = false
450- textView.isRichText = false
451- textView.isAutomaticQuoteSubstitutionEnabled = false
452- textView.isAutomaticTextReplacementEnabled = false
453- textView.isAutomaticDashSubstitutionEnabled = false
454- textView.isAutomaticSpellingCorrectionEnabled = false
455- textView.font = .systemFont(ofSize: 14, weight: .regular)
456- textView.textContainer?.lineBreakMode = .byWordWrapping
457- textView.textContainer?.lineFragmentPadding = 0
458- textView.textContainerInset = NSSize(width: 2, height: 4)
459- textView.focusRingType = .none
460-461- textView.minSize = .zero
462- textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
463- textView.isHorizontallyResizable = false
464- textView.isVerticallyResizable = true
465- textView.autoresizingMask = [.width]
466- textView.textContainer?.containerSize = NSSize(width: 0, height: CGFloat.greatestFiniteMagnitude)
467- textView.textContainer?.widthTracksTextView = true
447+let textView = ChatComposerTextViewFactory.makeConfiguredTextView()
448+guard let composerTextView = textView as? ChatComposerNSTextView else {
449+preconditionFailure("ChatComposerTextViewFactory must return ChatComposerNSTextView")
450+}
451+ composerTextView.delegate = context.coordinator
468452469-textView.string = self.text
470-textView.onSend = { [weak textView] in
471-textView?.window?.makeFirstResponder(nil)
453+composerTextView.string = self.text
454+composerTextView.onSend = { [weak composerTextView] in
455+composerTextView?.window?.makeFirstResponder(nil)
472456self.onSend()
473457}
474-textView.onPasteImageAttachment = self.onPasteImageAttachment
458+composerTextView.onPasteImageAttachment = self.onPasteImageAttachment
475459476460let scroll = NSScrollView()
477461 scroll.drawsBackground = false
@@ -522,6 +506,34 @@ private struct ChatComposerTextView: NSViewRepresentable {
522506}
523507}
524508509+enum ChatComposerTextViewFactory {
510+ // Internal for @testable import coverage of composer text view defaults.
511+@MainActor
512+static func makeConfiguredTextView() -> NSTextView {
513+let textView = ChatComposerNSTextView()
514+ textView.drawsBackground = false
515+ textView.isRichText = false
516+ textView.isAutomaticQuoteSubstitutionEnabled = false
517+ textView.isAutomaticTextReplacementEnabled = false
518+ textView.isAutomaticDashSubstitutionEnabled = false
519+ textView.isAutomaticSpellingCorrectionEnabled = false
520+ textView.font = .systemFont(ofSize: 14, weight: .regular)
521+ textView.textContainer?.lineBreakMode = .byWordWrapping
522+ textView.textContainer?.lineFragmentPadding = 0
523+ textView.textContainerInset = NSSize(width: 2, height: 4)
524+ textView.focusRingType = .none
525+ textView.allowsUndo = true
526+ textView.minSize = .zero
527+ textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
528+ textView.isHorizontallyResizable = false
529+ textView.isVerticallyResizable = true
530+ textView.autoresizingMask = [.width]
531+ textView.textContainer?.containerSize = NSSize(width: 0, height: CGFloat.greatestFiniteMagnitude)
532+ textView.textContainer?.widthTracksTextView = true
533+return textView
534+}
535+}
536+525537private final class ChatComposerNSTextView: NSTextView {
526538var onSend: (() -> Void)?
527539var onPasteImageAttachment: ((_ data: Data, _ fileName: String, _ mimeType: String) -> Void)?
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。