Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some actions repeatable #1706

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/contour/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include <crispy/assert.h>
#include <crispy/utils.h>

#include <format>
#include <optional>
Expand Down Expand Up @@ -151,6 +152,23 @@ using Action = std::variant<CancelSelection,
SwitchToTabLeft,
SwitchToTabRight>;

template <typename T>
concept RepeatableActionConcept = crispy::one_of<T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what is better, either note the repeatable ones, or the ones that should be protected from key-repeat. 🤔

DecreaseFontSize,
DecreaseOpacity,
IncreaseFontSize,
IncreaseOpacity,
ScrollDown,
ScrollMarkDown,
ScrollMarkUp,
ScrollOneDown,
ScrollOneUp,
ScrollPageDown,
ScrollPageUp,
ScrollToBottom,
ScrollToTop,
ScrollUp>;

std::optional<Action> fromString(std::string const& name);

namespace documentation
Expand Down
18 changes: 18 additions & 0 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,24 @@ void TerminalSession::sendKeyEvent(Key key, Modifiers modifiers, KeyboardEventTy
{
if (eventType == KeyboardEventType::Press)
executeAllActions(*actions);
else if (eventType == KeyboardEventType::Repeat)
{
// filter out actions that are not repeatable
std::vector<actions::Action> tmpActions;

auto set = crispy::overloaded {
[&](actions::RepeatableActionConcept auto const& action) {
tmpActions.emplace_back(action);
},
[&]([[maybe_unused]] auto const& action) {},
};

for (auto const& action: *actions)
{
std::visit(set, action);
}
executeAllActions(tmpActions);
}
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/crispy/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,7 @@ struct overloaded: Ts...
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

template <typename T, typename... Ts>
concept one_of = (std::same_as<T, Ts> || ...);

} // namespace crispy
Loading