esc is slow
This commit is contained in:
parent
6a381b539c
commit
b72c959a54
@ -139,26 +139,46 @@ std::string fullscreen_window::set_input_multiple_choice(std::string prompt, std
|
||||
|
||||
int selected = 0;
|
||||
std::string filter = "";
|
||||
std::string last_filter = "";
|
||||
auto last_key_time = std::chrono::steady_clock::now();
|
||||
int scroll_offset = 0;
|
||||
std::vector<std::string> last_filtered_choices;
|
||||
int last_selected = -1;
|
||||
int last_scroll_offset = -1;
|
||||
|
||||
// Pre-compute lowercase versions of choices for case-insensitive matching
|
||||
std::vector<std::string> lowercase_choices;
|
||||
lowercase_choices.reserve(choices.size());
|
||||
for (const auto& choice : choices) {
|
||||
std::string lower;
|
||||
lower.reserve(choice.size());
|
||||
std::transform(choice.begin(), choice.end(), std::back_inserter(lower), ::tolower);
|
||||
lowercase_choices.push_back(std::move(lower));
|
||||
}
|
||||
|
||||
// Initial filtered choices (all choices)
|
||||
std::vector<std::string> filtered_choices = choices;
|
||||
|
||||
while (true) {
|
||||
// Filter choices based on input
|
||||
std::vector<std::string> filtered_choices;
|
||||
for (const auto& choice : choices) {
|
||||
if (filter.empty() || choice.find(filter) == 0) {
|
||||
filtered_choices.push_back(choice);
|
||||
// Only recalculate filtered choices if filter changed
|
||||
if (filter != last_filter) {
|
||||
if (filter.empty()) {
|
||||
filtered_choices = choices;
|
||||
} else {
|
||||
filtered_choices.clear();
|
||||
// Convert filter to lowercase once
|
||||
std::string lowercase_filter;
|
||||
lowercase_filter.reserve(filter.size());
|
||||
std::transform(filter.begin(), filter.end(), std::back_inserter(lowercase_filter), ::tolower);
|
||||
|
||||
// Filter using pre-computed lowercase versions
|
||||
for (size_t i = 0; i < choices.size(); ++i) {
|
||||
if (lowercase_choices[i].find(lowercase_filter) == 0) {
|
||||
filtered_choices.push_back(choices[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filtered_choices.empty()) {
|
||||
filtered_choices = choices;
|
||||
filter = "";
|
||||
}
|
||||
|
||||
// Get window dimensions
|
||||
int max_y, max_x;
|
||||
getmaxyx(input_win, max_y, max_x);
|
||||
@ -179,11 +199,8 @@ std::string fullscreen_window::set_input_multiple_choice(std::string prompt, std
|
||||
}
|
||||
}
|
||||
|
||||
// Only redraw if something changed
|
||||
if (filtered_choices != last_filtered_choices ||
|
||||
selected != last_selected ||
|
||||
scroll_offset != last_scroll_offset) {
|
||||
|
||||
// Only redraw if selection or scroll changed
|
||||
if (selected != last_selected || scroll_offset != last_scroll_offset || last_filter != filter) {
|
||||
// Clear the input window except for the prompt
|
||||
werase(input_win);
|
||||
box(input_win, 0, 0);
|
||||
@ -218,9 +235,9 @@ std::string fullscreen_window::set_input_multiple_choice(std::string prompt, std
|
||||
wrefresh(input_win);
|
||||
|
||||
// Update last state
|
||||
last_filtered_choices = filtered_choices;
|
||||
last_selected = selected;
|
||||
last_scroll_offset = scroll_offset;
|
||||
last_filter = filter;
|
||||
}
|
||||
|
||||
int ch = wgetch(input_win);
|
||||
|
Loading…
x
Reference in New Issue
Block a user