-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make coordinator properly handle indentation
- Loading branch information
1 parent
3c0a29e
commit fb1f6f9
Showing
7 changed files
with
58 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Sources/RichTextKit/Attributes/RichTextAttributeWriter+Paragraph.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// RichTextAttributeWriter+Paragraph.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-02-14. | ||
// Copyright © 2023-2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if canImport(UIKit) | ||
import UIKit | ||
#endif | ||
|
||
#if canImport(AppKit) && !targetEnvironment(macCatalyst) | ||
import AppKit | ||
#endif | ||
|
||
public extension RichTextAttributeWriter { | ||
|
||
/// Set the rich text paragraph style at a certain range. | ||
func setRichTextParagraphStyle( | ||
to style: NSParagraphStyle, | ||
at range: NSRange | ||
) { | ||
let text = richText.string | ||
let length = range.length | ||
let location = range.location | ||
let ulocation = UInt(location) | ||
let uindex = text.findIndexOfCurrentParagraph(from: ulocation) | ||
let index = Int(uindex) | ||
let diff = location - index | ||
let newLength = max(length + diff, 1) | ||
let newRange = NSRange(location: index, length: newLength) | ||
let safeRange = safeRange(for: newRange) | ||
setRichTextAttribute(.paragraphStyle, to: style, at: safeRange) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters