Something went wrong. Try again.
A mirror to work around a broken repository.
Something went wrong. Try again.
851 B · 35 lines
Swift
at main
123456789101112131415161718192021222324252627282930313233343536//// CodeTextView.swift// Dissertation//// Created by Jon Sterling on 7/27/26.//
import AppKit
final class CodeTextView: NSTextView { static let typingAttributes: [NSAttributedString.Key: Any] = [ .font: NSFont.systemFont(ofSize: 14, weight: .regular), .foregroundColor: NSColor.textColor, ]
override var typingAttributes: [NSAttributedString.Key: Any] { get { Self.typingAttributes } set {} }
override func insertNewline(_ sender: Any?) { guard let textStorage else { super.insertNewline(sender) return }
let text = textStorage.string guard let selection = Range(selectedRange(), in: text) else { return } let lineRange = text.lineRange(for: selection) let line = text[lineRange] let indent = line.prefix { $0 == " " || $0 == "\t" } insertText("\n\(indent)", replacementRange: selectedRange) }}