Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mingsheng13 committed Aug 28, 2023
1 parent e79f171 commit e7db462
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/ftxui/component/component_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct InputOption {
std::function<Element(InputState)> transform;
Ref<bool> password = false; /// < Obscure the input content using '*'.
Ref<bool> multiline = true; /// < Whether the input can be multiline.
Ref<bool> overwrite = false; /// < Overwrite text at cursor.
Ref<bool> insert = true; /// < Insert or overtype character mode.

/// Called when the content changes.
std::function<void()> on_change = [] {};
Expand Down
16 changes: 7 additions & 9 deletions src/ftxui/component/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class InputBase : public ComponentBase, public InputOption {
// Component implementation:
Element Render() override {
const bool is_focused = Focused();
const auto focused =
(overwrite() && (is_focused || hovered_)) ? focusCursorBlockBlinking
: (is_focused || hovered_) ? focusCursorBarBlinking : select;
const auto focused = (!is_focused && !hovered_) ? select
: insert() ? focusCursorBarBlinking
: focusCursorBlockBlinking;

auto transform_func =
transform ? transform : InputOption::Default().transform;
Expand Down Expand Up @@ -343,12 +343,10 @@ class InputBase : public ComponentBase, public InputOption {
}

bool HandleCharacter(const std::string& character) {
if (overwrite()) {
content->replace(cursor_position(), character.size(), character);
}
else {
content->insert(cursor_position(), character);
if (!insert()) {
HandleDelete();
}
content->insert(cursor_position(), character);
cursor_position() += character.size();
on_change();
return true;
Expand Down Expand Up @@ -517,7 +515,7 @@ class InputBase : public ComponentBase, public InputOption {
}

bool HandleInsert() {
overwrite() = !overwrite();
insert() = !insert();
return true;
}

Expand Down

0 comments on commit e7db462

Please sign in to comment.