From e430cb45b25d9decc0e87773db5b67c6e34cf96f Mon Sep 17 00:00:00 2001 From: Toni Sevener Date: Fri, 5 Jan 2024 12:10:10 -0600 Subject: [PATCH] Add delegate callback methods, swiftlint changes --- .../WKEditorToolbarExpandingView.swift | 4 ++++ .../WKEditorToolbarHighlightView.swift | 2 ++ .../WKEditorToolbarPlainView.swift | 1 + .../WKEditorInputViewController.swift | 3 ++- .../WKSourceEditorViewController.swift | 19 ++++++++++++++++++- .../WKSourceEditorFormatterTests.swift | 10 +++++----- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Expanding/WKEditorToolbarExpandingView.swift b/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Expanding/WKEditorToolbarExpandingView.swift index bbf183ad600..51b0691c643 100644 --- a/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Expanding/WKEditorToolbarExpandingView.swift +++ b/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Expanding/WKEditorToolbarExpandingView.swift @@ -5,6 +5,8 @@ protocol WKEditorToolbarExpandingViewDelegate: AnyObject { func toolbarExpandingViewDidTapFormatText(toolbarView: WKEditorToolbarExpandingView) func toolbarExpandingViewDidTapFormatHeading(toolbarView: WKEditorToolbarExpandingView) func toolbarExpandingViewDidTapTemplate(toolbarView: WKEditorToolbarExpandingView, isSelected: Bool) + func toolbarExpandingViewDidTapLink(toolbarView: WKEditorToolbarExpandingView, isSelected: Bool) + func toolbarExpandingViewDidTapImage(toolbarView: WKEditorToolbarExpandingView) } class WKEditorToolbarExpandingView: WKEditorToolbarView { @@ -204,6 +206,7 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView { } @objc private func tappedLink() { + delegate?.toolbarExpandingViewDidTapLink(toolbarView: self, isSelected: linkButton.isSelected) } @objc private func tappedUnorderedList() { @@ -239,6 +242,7 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView { } @objc private func tappedMedia() { + delegate?.toolbarExpandingViewDidTapImage(toolbarView: self) } } diff --git a/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Highlight/WKEditorToolbarHighlightView.swift b/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Highlight/WKEditorToolbarHighlightView.swift index 7003ab32d0c..92606443801 100644 --- a/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Highlight/WKEditorToolbarHighlightView.swift +++ b/Components/Sources/Components/Components/Editors/Common Views/Input Accessory Views/Highlight/WKEditorToolbarHighlightView.swift @@ -4,6 +4,7 @@ protocol WKEditorToolbarHighlightViewDelegate: AnyObject { func toolbarHighlightViewDidTapBold(toolbarView: WKEditorToolbarHighlightView, isSelected: Bool) func toolbarHighlightViewDidTapItalics(toolbarView: WKEditorToolbarHighlightView, isSelected: Bool) func toolbarHighlightViewDidTapTemplate(toolbarView: WKEditorToolbarHighlightView, isSelected: Bool) + func toolbarHighlightViewDidTapLink(toolbarView: WKEditorToolbarHighlightView, isSelected: Bool) func toolbarHighlightViewDidTapShowMore(toolbarView: WKEditorToolbarHighlightView) func toolbarHighlightViewDidTapFormatHeading(toolbarView: WKEditorToolbarHighlightView) } @@ -100,6 +101,7 @@ class WKEditorToolbarHighlightView: WKEditorToolbarView { } @objc private func tappedLink() { + delegate?.toolbarHighlightViewDidTapLink(toolbarView: self, isSelected: linkButton.isSelected) } @objc private func tappedTemplate() { diff --git a/Components/Sources/Components/Components/Editors/Common Views/Input Views/Main/Plain Toolbar Table Item/WKEditorToolbarPlainView.swift b/Components/Sources/Components/Components/Editors/Common Views/Input Views/Main/Plain Toolbar Table Item/WKEditorToolbarPlainView.swift index 8f9a0be668d..0e4ebf054a1 100644 --- a/Components/Sources/Components/Components/Editors/Common Views/Input Views/Main/Plain Toolbar Table Item/WKEditorToolbarPlainView.swift +++ b/Components/Sources/Components/Components/Editors/Common Views/Input Views/Main/Plain Toolbar Table Item/WKEditorToolbarPlainView.swift @@ -78,5 +78,6 @@ class WKEditorToolbarPlainView: WKEditorToolbarView { } @objc private func tappedLink() { + delegate?.didTapLink(isSelected: linkButton.isSelected) } } diff --git a/Components/Sources/Components/Components/Editors/Common Views/Input Views/WKEditorInputViewController.swift b/Components/Sources/Components/Components/Editors/Common Views/Input Views/WKEditorInputViewController.swift index 1ffe9565031..fff38b7b15e 100644 --- a/Components/Sources/Components/Components/Editors/Common Views/Input Views/WKEditorInputViewController.swift +++ b/Components/Sources/Components/Components/Editors/Common Views/Input Views/WKEditorInputViewController.swift @@ -2,11 +2,12 @@ import Foundation import UIKit protocol WKEditorInputViewDelegate: AnyObject { - func didTapClose() func didTapBold(isSelected: Bool) func didTapItalics(isSelected: Bool) func didTapTemplate(isSelected: Bool) func didTapStrikethrough(isSelected: Bool) + func didTapLink(isSelected: Bool) + func didTapClose() } class WKEditorInputViewController: WKComponentViewController { diff --git a/Components/Sources/Components/Components/Editors/Source Editor/WKSourceEditorViewController.swift b/Components/Sources/Components/Components/Editors/Source Editor/WKSourceEditorViewController.swift index 1eb2abfc40c..d3f645adf52 100644 --- a/Components/Sources/Components/Components/Editors/Source Editor/WKSourceEditorViewController.swift +++ b/Components/Sources/Components/Components/Editors/Source Editor/WKSourceEditorViewController.swift @@ -310,12 +310,20 @@ extension WKSourceEditorViewController: WKEditorToolbarExpandingViewDelegate { let action: WKSourceEditorFormatterButtonAction = isSelected ? .remove : .add textFrameworkMediator.templateFormatter?.toggleTemplateFormatting(action: action, in: textView) } + + func toolbarExpandingViewDidTapLink(toolbarView: WKEditorToolbarExpandingView, isSelected: Bool) { + + } + + func toolbarExpandingViewDidTapImage(toolbarView: WKEditorToolbarExpandingView) { + + } } // MARK: - WKEditorToolbarHighlightViewDelegate extension WKSourceEditorViewController: WKEditorToolbarHighlightViewDelegate { - + func toolbarHighlightViewDidTapBold(toolbarView: WKEditorToolbarHighlightView, isSelected: Bool) { let action: WKSourceEditorFormatterButtonAction = isSelected ? .remove : .add textFrameworkMediator.boldItalicsFormatter?.toggleBoldFormatting(action: action, in: textView) @@ -331,6 +339,10 @@ extension WKSourceEditorViewController: WKEditorToolbarHighlightViewDelegate { textFrameworkMediator.templateFormatter?.toggleTemplateFormatting(action: action, in: textView) } + func toolbarHighlightViewDidTapLink(toolbarView: WKEditorToolbarHighlightView, isSelected: Bool) { + + } + func toolbarHighlightViewDidTapShowMore(toolbarView: WKEditorToolbarHighlightView) { inputViewType = .main postUpdateButtonSelectionStatesNotification(withDelay: true) @@ -344,6 +356,7 @@ extension WKSourceEditorViewController: WKEditorToolbarHighlightViewDelegate { // MARK: - WKEditorInputViewDelegate extension WKSourceEditorViewController: WKEditorInputViewDelegate { + func didTapBold(isSelected: Bool) { let action: WKSourceEditorFormatterButtonAction = isSelected ? .remove : .add textFrameworkMediator.boldItalicsFormatter?.toggleBoldFormatting(action: action, in: textView) @@ -364,6 +377,10 @@ extension WKSourceEditorViewController: WKEditorInputViewDelegate { textFrameworkMediator.strikethroughFormatter?.toggleStrikethroughFormatting(action: action, in: textView) } + func didTapLink(isSelected: Bool) { + + } + func didTapClose() { inputViewType = nil let isRangeSelected = textView.selectedRange.length > 0 diff --git a/Components/Tests/ComponentsTests/WKSourceEditorFormatterTests.swift b/Components/Tests/ComponentsTests/WKSourceEditorFormatterTests.swift index f54b394874f..5a14925c774 100644 --- a/Components/Tests/ComponentsTests/WKSourceEditorFormatterTests.swift +++ b/Components/Tests/ComponentsTests/WKSourceEditorFormatterTests.swift @@ -901,31 +901,31 @@ final class WKSourceEditorFormatterTests: XCTestCase { var linkRange5 = NSRange(location: 0, length: 0) let linkAttributes5 = mutAttributedString.attributes(at: 53, effectiveRange: &linkRange5) - //"[[File:Cat with fish.jpg|thumb|left|Cat with " + // "[[File:Cat with fish.jpg|thumb|left|Cat with " XCTAssertEqual(linkRange1.location, 0, "Incorrect link formatting") XCTAssertEqual(linkRange1.length, 45, "Incorrect link formatting") XCTAssertEqual(linkAttributes1[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting") XCTAssertEqual(linkAttributes1[.foregroundColor] as! UIColor, colors.blueForegroundColor, "Incorrect link formatting") - //"[[" + // "[[" XCTAssertEqual(linkRange2.location, 45, "Incorrect link formatting") XCTAssertEqual(linkRange2.length, 2, "Incorrect link formatting") XCTAssertEqual(linkAttributes2[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting") XCTAssertEqual(linkAttributes2[.foregroundColor] as! UIColor, colors.blueForegroundColor, "Incorrect link formatting") - //"fish" + // "fish" XCTAssertEqual(linkRange3.location, 47, "Incorrect link formatting") XCTAssertEqual(linkRange3.length, 4, "Incorrect link formatting") XCTAssertEqual(linkAttributes3[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting") XCTAssertEqual(linkAttributes3[.foregroundColor] as! UIColor, colors.blueForegroundColor, "Incorrect link formatting") - //"]]" + // "]]" XCTAssertEqual(linkRange4.location, 51, "Incorrect link formatting") XCTAssertEqual(linkRange4.length, 2, "Incorrect link formatting") XCTAssertEqual(linkAttributes4[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting") XCTAssertEqual(linkAttributes4[.foregroundColor] as! UIColor, colors.blueForegroundColor, "Incorrect link formatting") - //"|alt=Photo of cat looking at fish]]" + // "|alt=Photo of cat looking at fish]]" XCTAssertEqual(linkRange5.location, 53, "Incorrect link formatting") XCTAssertEqual(linkRange5.length, 35, "Incorrect link formatting") XCTAssertEqual(linkAttributes5[.font] as! UIFont, fonts.baseFont, "Incorrect base formatting")