Feature: input can now use overwrite mode when toggled with insert key (#735)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
MingSheng
2023-08-28 20:07:26 +01:00
committed by GitHub
parent cdf28903a7
commit 05c7bee6dd
6 changed files with 50 additions and 4 deletions

View File

@@ -100,8 +100,9 @@ class InputBase : public ComponentBase, public InputOption {
// Component implementation:
Element Render() override {
const bool is_focused = Focused();
const auto focused =
(is_focused || hovered_) ? focusCursorBarBlinking : select;
const auto focused = (!is_focused && !hovered_) ? select
: insert() ? focusCursorBarBlinking
: focusCursorBlockBlinking;
auto transform_func =
transform ? transform : InputOption::Default().transform;
@@ -342,10 +343,13 @@ class InputBase : public ComponentBase, public InputOption {
}
bool HandleCharacter(const std::string& character) {
if (!insert() && cursor_position() < (int)content->size() &&
content()[cursor_position()] != '\n') {
HandleDelete();
}
content->insert(cursor_position(), character);
cursor_position() += character.size();
on_change();
return true;
}
@@ -391,7 +395,9 @@ class InputBase : public ComponentBase, public InputOption {
if (event == Event::ArrowRightCtrl) {
return HandleRightCtrl();
}
if (event == Event::Insert) {
return HandleInsert();
}
return false;
}
@@ -509,6 +515,11 @@ class InputBase : public ComponentBase, public InputOption {
return true;
}
bool HandleInsert() {
insert() = !insert();
return true;
}
bool Focusable() const final { return true; }
bool hovered_ = false;