From 606e0efdfe7c7f21be2167b352226f3037e33c4b Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 20 Sep 2020 11:47:06 +0200 Subject: [PATCH] Implement Input::on_change. --- include/ftxui/component/input.hpp | 4 ++-- src/ftxui/component/input.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/ftxui/component/input.hpp b/include/ftxui/component/input.hpp index d20cc85..92f3d21 100644 --- a/include/ftxui/component/input.hpp +++ b/include/ftxui/component/input.hpp @@ -20,8 +20,8 @@ class Input : public Component { std::wstring placeholder; // State update callback. - std::function on_change = []() {}; - std::function on_enter = []() {}; + std::function on_change = [] {}; + std::function on_enter = [] {}; // Component implementation. Element Render() override; diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index db04765..7a76055 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -52,6 +52,7 @@ bool Input::OnEvent(Event event) { return false; content.erase(cursor_position - 1, 1); cursor_position--; + on_change(); return true; } @@ -60,6 +61,7 @@ bool Input::OnEvent(Event event) { if (cursor_position == int(content.size())) return false; content.erase(cursor_position, 1); + on_change(); return true; } @@ -87,6 +89,7 @@ bool Input::OnEvent(Event event) { if (event.is_character()) { content.insert(cursor_position, 1, event.character()); cursor_position++; + on_change(); return true; } return false;