Skip to content

Commit

Permalink
# Fix Theme Re-Create
Browse files Browse the repository at this point in the history
Fixed the issue where the default theme was always recreated.
  • Loading branch information
mc-public committed Aug 19, 2024
1 parent 81e23a9 commit f06aac2
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/Runestone/Library/UITextInput+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit
extension UITextInput where Self: NSObject {
var sbs_textSelectionDisplayInteraction: UITextSelectionDisplayInteraction? {
let interactionAssistantKey = "int" + "ssAnoitcare".reversed() + "istant"
let selectionViewManagerKey = "les_".reversed() + "ection" + "reganaMweiV".reversed()
let selectionViewManagerKey: String = "les_".reversed() + "ection" + "reganaMweiV".reversed()
guard responds(to: Selector(interactionAssistantKey)) else {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Runestone/StringSyntaxHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class StringSyntaxHighlighter {
/// - language: The language to use when parsing the text
/// - languageProvider: Object that can provide embedded languages on demand. A strong reference will be stored to the language provider..
public init(
theme: Theme = DefaultTheme(),
theme: Theme = DefaultTheme.share,
language: TreeSitterLanguage,
languageProvider: TreeSitterLanguageProvider? = nil
) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Runestone/TextView/Appearance/DefaultTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public final class DefaultTheme: Runestone.Theme {
public let selectionColor = UIColor(themeColorNamed: "selection")

public init() {}

public static let share = DefaultTheme()

// swiftlint:disable:next cyclomatic_complexity
public func textColor(for highlightName: String) -> UIColor? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Runestone/TextView/Core/LayoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class LayoutManager {
}
}
}
var theme: Theme = DefaultTheme() {
var theme: Theme = DefaultTheme.share {
didSet {
if theme !== oldValue {
gutterBackgroundView.backgroundColor = theme.gutterBackgroundColor
Expand Down
2 changes: 1 addition & 1 deletion Sources/Runestone/TextView/Core/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ open class TextView: UIScrollView {
/// Create a new text view.
/// - Parameter frame: The frame rectangle of the text view.
override public init(frame: CGRect) {
textInputView = TextInputView(theme: DefaultTheme())
textInputView = TextInputView(theme: DefaultTheme.share)
super.init(frame: frame)
backgroundColor = .white
textInputView.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class LineController {
}
}
}
var theme: Theme = DefaultTheme() {
var theme: Theme = DefaultTheme.share {
didSet {
syntaxHighlighter?.theme = theme
applyThemeToAllLineFragmentControllers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CoreGraphics
import Foundation

final class PlainTextSyntaxHighlighter: LineSyntaxHighlighter {
var theme: Theme = DefaultTheme()
var theme: Theme = DefaultTheme.share
var kern: CGFloat = 0
var canHighlight: Bool {
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum TreeSitterSyntaxHighlighterError: LocalizedError {
}

final class TreeSitterSyntaxHighlighter: LineSyntaxHighlighter {
var theme: Theme = DefaultTheme()
var theme: Theme = DefaultTheme.share
var kern: CGFloat = 0
var canHighlight: Bool {
languageMode.canHighlight
Expand Down

0 comments on commit f06aac2

Please sign in to comment.