Skip to content

Commit

Permalink
Bug fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener committed Jan 9, 2024
1 parent 743eb8e commit b5e7429
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ protocol WKEditorInputViewDelegate: AnyObject {
func didTapBold(isSelected: Bool)
func didTapItalics(isSelected: Bool)
func didTapTemplate(isSelected: Bool)
func didTapHeading(type: WKEditorInputView.HeadingButtonType)
func didTapStrikethrough(isSelected: Bool)
}

Expand Down Expand Up @@ -221,6 +222,18 @@ class WKEditorInputView: WKComponentView {
])

updateColors()

NotificationCenter.default.addObserver(self, selector: #selector(updateButtonSelectionState(_:)), name: Notification.WKSourceEditorSelectionState, object: nil)
}

// MARK: - Notifications

@objc private func updateButtonSelectionState(_ notification: NSNotification) {
guard let selectionState = notification.userInfo?[Notification.WKSourceEditorSelectionStateKey] as? WKSourceEditorSelectionState else {
return
}

configure(selectionState: selectionState)
}

// MARK: - Overrides
Expand Down Expand Up @@ -283,20 +296,40 @@ class WKEditorInputView: WKComponentView {

switch type {
case .paragraph:
paragraphButton.isSelected.toggle()
paragraphButton.isSelected = true
case .heading:
headerButton.isSelected.toggle()
headerButton.isSelected = true
case .subheading1:
subheader1Button.isSelected.toggle()
subheader1Button.isSelected = true
case .subheading2:
subheader2Button.isSelected.toggle()
subheader2Button.isSelected = true
case .subheading3:
subheader3Button.isSelected.toggle()
subheader3Button.isSelected = true
case .subheading4:
subheader4Button.isSelected.toggle()
subheader4Button.isSelected = true
}

delegate?.didTapHeading(type: type)
})

return UIButton(configuration: configuration, primaryAction: action)
}

func configure(selectionState: WKSourceEditorSelectionState) {
headingButtons.forEach { $0.isSelected = false }

if selectionState.isHeading {
headerButton.isSelected = true
} else if selectionState.isSubheading1 {
subheader1Button.isSelected = true
} else if selectionState.isSubheading2 {
subheader2Button.isSelected = true
} else if selectionState.isSubheading3 {
subheader3Button.isSelected = true
} else if selectionState.isSubheading4 {
subheader4Button.isSelected = true
} else {
paragraphButton.isSelected = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import ComponentsObjC

extension WKSourceEditorFormatterHeading {
func toggleHeadingFormatting(selectedHeading: WKEditorHeaderSelectViewModel.Configuration, currentSelectionState: WKSourceEditorSelectionState, textView: UITextView) {
func toggleHeadingFormatting(selectedHeading: WKEditorInputView.HeadingButtonType, currentSelectionState: WKSourceEditorSelectionState, textView: UITextView) {

var currentStateIsParagraph = false
if currentSelectionState.isHeading {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ extension WKSourceEditorViewController: WKEditorToolbarHighlightViewDelegate {
// MARK: - WKEditorInputViewDelegate

extension WKSourceEditorViewController: WKEditorInputViewDelegate {
func didTapHeading(selectedHeading: WKEditorHeaderSelectViewModel.Configuration) {
textFrameworkMediator.headingFormatter?.toggleHeadingFormatting(selectedHeading: selectedHeading, currentSelectionState: selectionState(), textView: textView)
func didTapHeading(type: WKEditorInputView.HeadingButtonType) {
textFrameworkMediator.headingFormatter?.toggleHeadingFormatting(selectedHeading: type, currentSelectionState: selectionState(), textView: textView)
}

func didTapBold(isSelected: Bool) {
Expand Down

0 comments on commit b5e7429

Please sign in to comment.