Skip to content

Commit

Permalink
Add superscript buttons to macOS sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Feb 14, 2024
1 parent 0e14cd9 commit 439c78b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -28,4 +35,3 @@ public extension RichTextViewComponent {
setRichTextSuperscriptLevel(to: newSize)
}
}
#endif
30 changes: 26 additions & 4 deletions Sources/RichTextKit/Format/RichTextFormatSidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<Content: View>: View {

let title: String?
Expand Down

0 comments on commit 439c78b

Please sign in to comment.