All Projects → ChimeHQ → TextViewPlus

ChimeHQ / TextViewPlus

Licence: BSD-3-Clause license
Collection of useful extensions when working with NSTextView

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to TextViewPlus

LSPKit
Language Server Protocol (LSP) implementation for Cocoa ☕️
Stars: ✭ 33 (+17.86%)
Mutual labels:  cocoa, appkit
react-native-macos
Fork of https://github.com/ptmt/react-native-macos with more features
Stars: ✭ 22 (-21.43%)
Mutual labels:  cocoa, appkit
TextStory
Happier, more flexible NSTextStorage
Stars: ✭ 60 (+114.29%)
Mutual labels:  appkit, nstextview
ProcessEnv
Capture the shell environment of a Foundation app
Stars: ✭ 16 (-42.86%)
Mutual labels:  cocoa, appkit
WebPKit
A framework that extends a variety of Cocoa APIs with capabilities for encoding and decoding WebP files for all of Apple's platforms.
Stars: ✭ 29 (+3.57%)
Mutual labels:  cocoa, appkit
OutlineViewDiffableDataSource
Stop looking for NSOutlineViewDiffableDataSource, it’s here 👌
Stars: ✭ 96 (+242.86%)
Mutual labels:  cocoa, appkit
Rearrange
Collection of utilities for interacting with NSRange and NSTextRange
Stars: ✭ 28 (+0%)
Mutual labels:  cocoa, nstextview
XcoatOfPaint
Replace your Xcode icon with colorful variants
Stars: ✭ 131 (+367.86%)
Mutual labels:  cocoa, appkit
panthro
An implementation of XPath 3.0 in Objective-C/Cocoa
Stars: ✭ 45 (+60.71%)
Mutual labels:  cocoa
articles-ko
Articles for NSHipster.co.kr
Stars: ✭ 18 (-35.71%)
Mutual labels:  cocoa
Punic
Clean room reimplementation of Carthage tool
Stars: ✭ 236 (+742.86%)
Mutual labels:  cocoa
Equinox
🌇 🌃 Create dynamic wallpapers for macOS.
Stars: ✭ 737 (+2532.14%)
Mutual labels:  appkit
trace-cocoa-sdk
Catch bugs before they reach production — get detailed crash reports and monitor how your app is performing across the entire install base.
Stars: ✭ 15 (-46.43%)
Mutual labels:  cocoa
Carthage
A simple, decentralized dependency manager for Cocoa
Stars: ✭ 14,487 (+51639.29%)
Mutual labels:  cocoa
AppKitFocusOverlay
Add hotkey(s) to display the key focus path for any window in your AppKit application.
Stars: ✭ 42 (+50%)
Mutual labels:  appkit
Criollo
A powerful Cocoa web framework and HTTP server for macOS, iOS and tvOS.
Stars: ✭ 229 (+717.86%)
Mutual labels:  cocoa
OperationPlus
NSOperation's missing pieces
Stars: ✭ 119 (+325%)
Mutual labels:  cocoa
topologic
Visualiser for basic geometric primitives and fractals in arbitrary-dimensional spaces
Stars: ✭ 39 (+39.29%)
Mutual labels:  cocoa
objc-lisp-bridge
A portable reader and bridge for interacting with Objective-C and Cocoa
Stars: ✭ 39 (+39.29%)
Mutual labels:  cocoa
ostrich
A Game Boy Sound System player for macOS, written in Swift
Stars: ✭ 37 (+32.14%)
Mutual labels:  appkit

Github CI

TextViewPlus

TextViewPlus is a collection of utilities for making it easier to work with NSTextView and the text system.

Integration

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/ChimeHQ/TextViewPlus")
]

Extensions

Geometry

Wrappers around the underlying NSLayoutManager, but with a much more convenient API.

func enumerateLineFragments(for range: NSRange, block: (NSRect, NSRange) -> Void)
func enumerateLineFragments(for rect: NSRect, block: (NSRect, NSRange) -> Void)

Ranges

Handy methods for computing ranges of text within the view.

func textRange(for rect: NSRect) -> NSRange
var visibleTextRange: NSRange

Selection

Convenience methods for computing selection ranges/locations.

var selectedTextRanges: [NSRange]
var selectedContinuousRange: NSRange?
var insertionLocation: Int?

Style

Styling changes can be very expensive, this method is much faster in certain common cases.

func updateFont(_ newFont: NSFont, color newColor: NSColor)

Bounding

Computing bounding rectangles of displayed text.

func boundingRect(for range: NSRange) -> NSRect?
func boundingRect(forGlyphRange range: NSRange) -> NSRect?
func boundingSelectionRects(forRange range: NSRange) -> [NSRect]

Attributed Strings

Programmtic modification of the underlying attributed string in the NSTextStorage, with support for delegate callbacks and undo.

func replaceCharacters(in range: NSRange, with attributedString: NSAttributedString)

// with undo supported
func replaceString(in range: NSRange, with attributedString: NSAttributedString)

Behavior

Changing NSTextView behaviors can be tricky, and often involve complex interactions with the whole system (NSLayoutManager, NSTextContainer, NSScrollView, etc).

public var wrapsTextToHorizontalBounds: Bool

Workarounds

// Fixes a widely-seen selection drawing artifact
func applySelectionDrawingWorkaround()

In versions of macOS before 13, TextKit 2 doesn't correctly apply rendering attributes. You can sub in this NSTextLayoutFragment to workaround the issue.

extension YourClass: NSTextLayoutManagerDelegate {
    func textLayoutManager(_ textLayoutManager: NSTextLayoutManager, textLayoutFragmentFor location: NSTextLocation, in textElement: NSTextElement) -> NSTextLayoutFragment {
        let range = textElement.elementRange

        switch textElement {
        case let paragraph as NSTextParagraph:
            return ParagraphRenderingAttributeTextLayoutFragment(textParagraph: paragraph, range: range)
        default:
            return NSTextLayoutFragment(textElement: textElement, range: range)
        }
    }
}

Suggestions or Feedback

We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].