From 70cf088d6ab2998be8b6e63975b0a40b8d16a019 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Tue, 10 Aug 2021 22:22:50 +0200 Subject: [PATCH] Fix input. (#188) Instead of wrapping WideInputBase by composition, wrap it by inheritance. This resolve the focus that was broken. --- src/ftxui/component/input.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index d0904c4..b077ce9 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -181,36 +181,33 @@ class WideInputBase : public ComponentBase { // WideInputBase. // TODO(arthursonzogni): Provide an implementation handling std::string natively // and adds better support for combining characters. -class InputBase : public ComponentBase { +class InputBase : public WideInputBase { public: InputBase(StringRef content, ConstStringRef placeholder, Ref option) - : content_(std::move(content)), - wrapped_content_(to_wstring(*content_)), - wrapped_input_(&wrapped_content_, - std::move(placeholder), - std::move(option)) {} + : WideInputBase(&wrapped_content_, + std::move(placeholder), + std::move(option)), + content_(std::move(content)), + wrapped_content_(to_wstring(*content_)) {} Element Render() override { wrapped_content_ = to_wstring(*content_); - return wrapped_input_.Render(); + return WideInputBase::Render(); } bool OnEvent(Event event) override { wrapped_content_ = to_wstring(*content_); - if (wrapped_input_.OnEvent(event)) { + if (WideInputBase::OnEvent(event)) { *content_ = to_string(wrapped_content_); return true; } return false; } - bool Focusable() const final { return true; } - StringRef content_; std::wstring wrapped_content_; - WideInputBase wrapped_input_; }; /// @brief An input box for editing text.