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

fix: Always show the completion group name when navigate in the group #46

Merged
merged 2 commits into from
Aug 18, 2024
Merged
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
28 changes: 23 additions & 5 deletions girara/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,33 @@ bool girara_isc_completion(girara_session_t* session, girara_argument_t* argumen
unsigned int uh = ceil(n_completion_items / 2.0);
unsigned int lh = floor(n_completion_items / 2.0);

unsigned int current_item = g_list_position(entries, entries_current);
unsigned int current_item = g_list_position(entries, entries_current);
unsigned int current_group = current_item;

GList* tmp_group = entries_current;
bool has_group = false;
while (tmp_group != NULL) {
if (((girara_internal_completion_entry_t*)tmp_group->data)->group) {
has_group = true;
}
current_group--;
tmp_group = tmp_group->prev;
}

GList* tmpentry = entries;
girara_internal_completion_entry_t* tmp;
for (unsigned int i = 0; i < n_elements; i++) {
if ((i >= (current_item - lh) && (i <= current_item + uh)) || (i < n_completion_items && current_item < lh) ||
(i >= (n_elements - n_completion_items) && (current_item >= (n_elements - uh)))) {
gtk_widget_show(GTK_WIDGET(((girara_internal_completion_entry_t*)tmpentry->data)->widget));
tmp = (girara_internal_completion_entry_t*)tmpentry->data;
/* If there is less than n-completion-items that need to be shown, show everything.
* Else, show n-completion-items items
* Additionally, the current group name is always shown */
if ((n_elements <= n_completion_items) || (i >= (current_item - lh) && (i <= current_item + uh)) ||
(i < n_completion_items && current_item < lh) ||
(i >= (n_elements - n_completion_items) && (current_item >= (n_elements - uh))) ||
(has_group && i == current_group)) {
gtk_widget_show(GTK_WIDGET(tmp->widget));
} else {
gtk_widget_hide(GTK_WIDGET(((girara_internal_completion_entry_t*)tmpentry->data)->widget));
gtk_widget_hide(GTK_WIDGET(tmp->widget));
}

tmpentry = g_list_next(tmpentry);
Expand Down