diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift index 44104c3e8..2c880e5f0 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift @@ -6,19 +6,26 @@ // Copyright © 2022-2023 Daniel Saidi. All rights reserved. // -#if os(macOS) import Foundation public extension RichTextViewComponent { /// Get the rich text superscript level at current range. var richTextSuperscriptLevel: Int? { + #if macOS richTextAttribute(.superscript) + #else + nil + #endif } /// Set the rich text superscript level at current range. func setRichTextSuperscriptLevel(to val: Int) { + #if macOS setRichTextAttribute(.superscript, to: val) + #else + print("Unsupported platform") + #endif } /// Step the rich text font size at current range. @@ -28,4 +35,3 @@ public extension RichTextViewComponent { setRichTextSuperscriptLevel(to: newSize) } } -#endif diff --git a/Sources/RichTextKit/Format/RichTextFormatSidebar.swift b/Sources/RichTextKit/Format/RichTextFormatSidebar.swift index bb38cd9b6..a665100fe 100644 --- a/Sources/RichTextKit/Format/RichTextFormatSidebar.swift +++ b/Sources/RichTextKit/Format/RichTextFormatSidebar.swift @@ -56,10 +56,21 @@ public struct RichTextFormatSidebar: View { SidebarSection(title: nil) { RichTextAlignment.Picker(selection: $context.textAlignment) .pickerStyle(.segmented) - RichTextAction.ButtonGroup( - context: context, - actions: [.decreaseIndent(), .increaseIndent()] - ) + HStack { + RichTextAction.ButtonGroup( + context: context, + actions: [.decreaseIndent(), .increaseIndent()] + ) + if hasSuperscriptSupport { + RichTextAction.ButtonGroup( + context: context, + actions: [ + .increaseSuperscript(), + .decreaseSuperscript() + ] + ) + } + } } SidebarSection(title: nil) { @@ -83,6 +94,17 @@ public struct RichTextFormatSidebar: View { } } +private extension RichTextFormatSidebar { + + var hasSuperscriptSupport: Bool { + #if macOS + return true + #else + return false + #endif + } +} + private struct SidebarSection: View { let title: String?