Skip to content

Instantly share code, notes, and snippets.

@kirkbyo
kirkbyo / custom-nstextblock-bug.swift
Created July 15, 2021 19:53
NSTextView AppKit, custom subclass of NSTextBlock bug
import SwiftUI
struct ContentView: View {
var body: some View {
NativeEditor()
.frame(maxWidth: 400, maxHeight: 600)
}
}
struct NativeEditor: NSViewRepresentable {
@kirkbyo
kirkbyo / DynamicSpacerHeightLayoutManager.swift
Created January 16, 2022 20:57
Layout according to offset without having elements overlap. Helper for SwiftUI implementation
class DynamicSpacerHeightLayoutManager<ID: Equatable & Hashable>: ObservableObject {
struct Element {
let offset: CGFloat
let height: CGFloat
}
@Published private var orderedByOffset = OrderedDictionary<ID, Element>()
// insert: O(n) <- can be optimized further
// append: O(1)
// update offset: O(n) <- can be optimized furhter