Skip to content

Instantly share code, notes, and snippets.

View krzyzanowskim's full-sized avatar

Marcin Krzyzanowski krzyzanowskim

View GitHub Profile
@krzyzanowskim
krzyzanowskim / .lessfilter
Last active November 8, 2024 14:46
less command with markdown highlighting
#!/bin/sh
# SETUP
#
# create executable file ~/.lessfilter with the content of this file
# chmod u+x ~/.lessfilter
#
# setup less by adding lines below to ~/.zshrc
# ```
# export LESSOPEN="| ~/.lessfilter %s"
@krzyzanowskim
krzyzanowskim / filewrapper.swift
Last active October 22, 2024 23:18
Filewrapper does not reread (refresh) its content
import Foundation
let dirURL = URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test")
// cleanup
try? FileManager.default.removeItem(at: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/COPY.png"))
let fw = try FileWrapper(url: dirURL)
// fw.fileWrappers // ["IMG_0736.png": <NSFileWrapper: 0x6000023a8420>]
@krzyzanowskim
krzyzanowskim / FB15439084.md
Last active November 8, 2024 19:58
FB15439084: NSTextList is Equatable in Swift but not equatable in common sense

NSTextList is Equatable because NSObject is always Equatable, however if anyone expect that may compare two instances of NSTextList that is false. This is because NSTextList.isEqual() do return true value for equal instances. This situation makes impossible to eg. compare NSParagraphStyle instances with testLists property as it will always fail. This situation seems easy fixable and will significanlty improve testability of the codebases (eg. mine)

        do {
            let a = NSTextList(markerFormat: .disc, options: 0) // Equatable
            let b = NSTextList(markerFormat: .disc, options: 0) // Equatable
            let c = a == b        // false
            let co = a.isEqual(b) // false
        }
@krzyzanowskim
krzyzanowskim / FB15281730.md
Created September 26, 2024 12:18
FB15281730: UITextInput marked text (IME) methods not called for certain languages on certain devices (or systems)

UITextView does not call its marked text methods (setMarkedText, setAttributedMarkedText) for some languages, and does for other languages, but also for the same language it does not call on iOS, but does call on Catalyst (designed for iPad). Here's the example:

class TestView: UITextView {

    override func setMarkedText(_ markedText: String?, selectedRange: NSRange) {
        super.setMarkedText(markedText, selectedRange: selectedRange) // not called
    }

 override func setAttributedMarkedText(_ markedText: NSAttributedString?, selectedRange: NSRange) {
@krzyzanowskim
krzyzanowskim / FB15131180-extraline.md
Last active September 14, 2024 17:20
FB15131180 TextKit extra line frame is incorrect and does not respect layout fragment size (Regression)

Starting macOS 15/iOS 18 TextKit 2 extra line frame is more broken (height always been broken) than previously. The same code return different values when run on macOS 14/iOS 17 and macOS 15/iOS 18.

The problem is that extra line fragment (NSTextLineFragment) origin and size is incorrect. I sketch the problem with the code snippet below:

// Storage
let textContentManager = NSTextContentStorage()

// Layout
@krzyzanowskim
krzyzanowskim / .gitconfig
Last active October 31, 2024 20:13
commit-ai
[alias]
# need llm CLI: https://llm.datasette.io/en/stable/
# based on https://gist.github.com/karpathy/1dd0294ef9567971c1e4348a90d69285?permalink_comment_id=5167582#gistcomment-5167582
commit-ai = "!f() { if [ -n \"$(git diff --cached)\" ]; then git commit -m \"$(git diff --cached | llm -m '4o-mini' 'Below is a diff of all staged changes, coming from the command:\\n```\\ngit diff --cached\\n```\\nPlease generate a concise, two-sentence, maximum 100 characteres commit message for these changes. Do not mention project name.')\"; else echo 'No changes to commit'; fi }; f"
@krzyzanowskim
krzyzanowskim / FB14893227.md
Last active August 22, 2024 22:23
FB14893227 UITextView convenience initializer does not call designated initializer since iOS 16

https://mastodon.social/@krzyzanowskim/113007925115490633

UITextView convenience initializer does not call designated initializer since iOS 16. The UITextView.init(usingTextLayoutManager:) that is a "convenience" initializer for the UITextView, does not call UITextView.init(frame:textContainer:) that is a designated initializer. This behavior, when the class interface traslated to Swift interface, breaks the Swift rules of object initialization. I believe that is also incorrect in Objective-C, although the compiler doesn't check that.

code snippet to reproduce:

final class CustomTextView: UITextView {
@krzyzanowskim
krzyzanowskim / FB14700414.md
Created August 8, 2024 21:28
FB14700414: NSTextList doesn't work since macOS 14 (regression)
@krzyzanowskim
krzyzanowskim / FB14165227.md
Last active October 2, 2024 11:29
FB14165227: UlTextView erroneously overrides string attributes when applying spellchecker annotation attributes

UITextView erroneously overrides string attributes when applying spellchecker annotation attributes.

It doesn't need any particular setting. Default UITextView instance with attributed text

let textView = UITextView(usingTextLayoutManager: true)
textView.spellCheckingType = .yes

Once spellcheck attributes get applied, other attributes like foregroundColor gets applied to the mispelled words. This behavior happens only on Mac Catalyst, and started to appear on macOS 14 or newer.

extension StringProtocol {
/// str[NSRange(location:0, length: 9)]
subscript(_ range: NSRange) -> SubSequence {
guard let stringRange = Range<String.Index>(range, in: self) else {
fatalError("String index is out of range")
}
return self[stringRange]
}