 class SectionEditorWebViewWithEditToolbar: SectionEditorWebView {
-    
+    weak var inputViewsSource: SectionEditorInputViewsSource?
+
     override init(theme: Theme) {
-        textFormattingInputViewController = TextFormattingInputViewController.wmf_viewControllerFromStoryboardNamed("TextFormatting")
         super.init(theme: theme)
         setEditMenuItems()
-        textFormattingInputViewController.delegate = self
-        defaultEditToolbarView?.delegate = self
-        contextualHighlightEditToolbarView?.delegate = self
-        NotificationCenter.default.addObserver(self, selector: #selector(textSelectionDidChange(_:)), name: Notification.Name.WMFSectionEditorSelectionChangedNotification, object: nil)
     }
 
     deinit {

        selectAllText()
    }

    // MARK: Accessory views
    private var defaultEditToolbarView = DefaultEditToolbarView.wmf_viewFromClassNib()
    private var contextualHighlightEditToolbarView = ContextualHighlightEditToolbarView.wmf_viewFromClassNib()

    // MARK: Input view

    private var inputViewType: TextFormattingInputViewController.InputViewType?

    private var textFormattingInputViewController: TextFormattingInputViewController

    override var inputViewController: UIInputViewController? {
        guard let inputViewType = inputViewType else {
            return nil
        }
        textFormattingInputViewController.inputViewType = inputViewType
        return textFormattingInputViewController
    }

    // MARK: - Showing input view

    func setInputViewHidden(type: TextFormattingInputViewController.InputViewType? = nil, hidden: Bool) {
        inputViewType = type

        if hidden {
            inputAccessoryViewType = previousInputAccessoryViewType
        } else {
            inputAccessoryViewType = nil
        }

        reloadInputViews()
    }

    // MARK: Input accessory view

    func configureInputAccessoryViews() {
        inputAccessoryViewType = .default
    }

    private var previousInputAccessoryViewType: InputAccessoryViewType?
    private var inputAccessoryViewType: InputAccessoryViewType? = .default {
        didSet {
            previousInputAccessoryViewType = oldValue
            inputAccessoryView = preferredInputAccessoryView()
            reloadInputViews()
        }
    }

    private enum InputAccessoryViewType {
        case `default`
        case highlight
    }

    override func reloadInputViews() {
        themeInputViews(theme: theme)
        super.reloadInputViews()
    }

    private func preferredInputAccessoryView() -> (UIView & Themeable)? {
        guard let inputAccessoryViewType = inputAccessoryViewType else {
            return nil
        }

        let maybeView: Any?

        switch inputAccessoryViewType {
        case .default:
            maybeView = defaultEditToolbarView
        case .highlight:
            maybeView = contextualHighlightEditToolbarView
        }

        guard let preferredInputAccessoryView = maybeView as? UIView & Themeable else {
            assertionFailure("Couldn't get preferredInputAccessoryView")
            return nil
        }

        return preferredInputAccessoryView
    }

    // MARK: Notifications

    @objc private func textSelectionDidChange(_ notification: Notification) {
        guard inputViewController == nil else {
            return
        }
        guard let userInfo = notification.userInfo else {
            return
        }
        guard let message = userInfo[SectionEditorWebViewConfiguration.WMFSectionEditorSelectionChanged] as? SelectionChangedMessage else {
            return
        }
        if message.selectionIsRange {
            inputAccessoryViewType = .highlight
        } else {
            inputAccessoryViewType = .default
        }
    }

    override func apply(theme: Theme) {

        themeInputViews(theme: theme)
    }
}
