Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikBucher12 committed Feb 13, 2024
1 parent 448b00f commit 2ab9384
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Actions/RichTextAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum RichTextAction: Identifiable, Equatable, RichTextLabelValue {

/// Undo the latest change.
case undoLatestChange

case link(url: URL?)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct CustomLinkAttributes {
self.link = link
self.color = color
}

let link: String
let color: ColorRepresentable
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public extension RichTextViewComponent {
string.addAttribute(.foregroundColor, value: ColorRepresentable.textColor, range: range)
string.fixAttributes(in: range)
}

string.endEditing()
}
self.typingAttributes = [.font: FontRepresentable.standardRichTextFont, .foregroundColor: ColorRepresentable.textColor]
setRichTextFont(.standardRichTextFont)
}

/// Set the current value of a certain rich text style.
func setCurrentRichTextLink(_ link: URL?) {
let shouldAdd = link != nil
Expand Down
4 changes: 2 additions & 2 deletions Sources/RichTextKit/Context/RichTextContext+Link.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import SwiftUI

public extension RichTextContext {

/// Get a binding for a certain color.
func binding(for link: URL?) -> Binding<URL?> {
Binding(
get: { self.link },
set: { self.setLink($0) }
)
}

/// Set the link to context
func setLink(_ url: URL?) {
self.link = url
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Context/RichTextContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public class RichTextContext: ObservableObject {
/// The current underline color, if any.
@Published
public internal(set) var underlineColor: ColorRepresentable?

/// The current link, if any.
@Published
public var link: URL?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension RichTextCoordinator {
func setLink(_ url: URL?) {
textView.setCurrentRichTextLink(url)
}

func pasteImage(_ data: RichTextInsertion<ImageRepresentable>?) {
guard let data = data else { return }
textView.pasteImage(
Expand Down
4 changes: 2 additions & 2 deletions Sources/RichTextKit/Coordinator/RichTextCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ open class RichTextCoordinator: NSObject {

/// Object responsible for setting links at given range
public let richTextLinkSetter: RichTextLinkSetter

/// The rich text to edit.
public var text: Binding<NSAttributedString>

Expand Down Expand Up @@ -219,7 +219,7 @@ extension RichTextCoordinator {
// textView.setRichTextAttribute(.richTextLink, to: nil)
// textView.setRichTextAttribute(.link, to: nil)
}

let background = textView.richTextColor(.background)
if richTextContext.backgroundColor != background {
richTextContext.backgroundColor = background
Expand Down
11 changes: 4 additions & 7 deletions Sources/RichTextKit/Coordinator/RichTextLinkSetter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import AppKit
import UIKit
#endif


public class RichTextLinkSetter {
#if macOS
let textView: NSTextView

/// - param textView: The text view which should be observed and highlighted.
/// - param notificationCenter: The notification center to subscribe in.
/// A testing seam. Defaults to `NotificationCenter.default`.
Expand Down Expand Up @@ -48,11 +47,9 @@ public class RichTextLinkSetter {
)
}
#endif



private var subscription: NSObjectProtocol!



#if macOS
func textViewDidChange(_ notification: Notification) {
textView.textStorage?.beginEditing()
Expand All @@ -66,5 +63,5 @@ public class RichTextLinkSetter {
textView.textStorage.endEditing()
}
#endif

}
2 changes: 1 addition & 1 deletion Sources/RichTextKit/RichTextView_AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ open class RichTextView: NSTextView, RichTextViewComponent {
}
)
}

/**
Alert a certain title and message.

Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/RichTextView_UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ open class RichTextView: UITextView, RichTextViewComponent {
}
)
}

/// Alert a certain title and message.
open func alert(title: String, message: String, buttonTitle: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
Expand Down
10 changes: 5 additions & 5 deletions Sources/RichTextKit/Styles/PresentationContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ private struct PresentationContainer<Value, SheetContent: View>: ViewModifier {
let style: PresentationStyle
let sheetContent: (Value?) -> SheetContent
let isPresented: Binding<Bool>

private struct SheetContentContainer: View {
@Binding var data: Value?
let sheetContent: (Value?) -> SheetContent

var body: some View {
sheetContent(data)
}
}

func body(content: Content) -> some View {
switch style {
case .sheet:
Expand All @@ -34,9 +34,9 @@ private struct PresentationContainer<Value, SheetContent: View>: ViewModifier {
content.alert(
"",
isPresented: isPresented,
actions: { SheetContentContainer(data: $data, sheetContent: sheetContent) }
actions: { SheetContentContainer(data: $data, sheetContent: sheetContent) }
)

}
}
}
Expand Down
13 changes: 6 additions & 7 deletions Sources/RichTextKit/Styles/RichTextLinkButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public struct RichTextLinkButton: View {
set: { _ in }
)
}

private let fillVertically: Bool

public init(
context: RichTextContext,
isAlertPresented: Binding<Bool>,
Expand All @@ -39,7 +39,7 @@ public struct RichTextLinkButton: View {
self._isAlertPresented = isAlertPresented
self.fillVertically = fillVertically
}

public var body: some View {
Button(
action: toggle,
Expand All @@ -56,7 +56,7 @@ public struct RichTextLinkButton: View {

struct ToggleButtonStyle: ButtonStyle {
var isToggled: Bool

func makeBody(configuration: Configuration) -> some View {
configuration.label
.background(isToggled ? Color.blue.opacity(0.2) : Color.clear)
Expand All @@ -66,12 +66,11 @@ struct ToggleButtonStyle: ButtonStyle {
}
}


extension RichTextLinkButton {
private var isOn: Bool {
context.binding(for: context.link).wrappedValue != nil
}

private func toggle() {
// This turns off/disables link.
if context.link != nil {
Expand All @@ -94,7 +93,7 @@ struct RichTextLinkButton_Previews: PreviewProvider {
}.padding(8)
}
}

static var previews: some View {
Preview()
}
Expand Down
1 change: 0 additions & 1 deletion Sources/RichTextKit/Styles/RichTextStyle+Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public extension RichTextStyle {
.foreground(.accentColor, if: isOn)
.contentShape(Rectangle())
}
.on
.buttonStyle(.plain)
.keyboardShortcut(for: style)
.accessibilityLabel(style.title)
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Styles/RichTextStyle+ToggleGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public extension RichTextStyle {

@State private var urlString = ""
@State private var isAlertPresented = false

private let styles: [RichTextStyle]
private let isGreedy: Bool

Expand Down

0 comments on commit 2ab9384

Please sign in to comment.