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

First step at enabling searching in index page #677

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

laomuon
Copy link
Contributor

@laomuon laomuon commented Sep 7, 2024

This PR is a proof of concept for enabling search in index page. It only use the native functionality of GTK.

The behavior:

  • Open the index page, press C-f (the default shortcut of GTK) to have the interactive search window appear
  • Start typing the keyword, the index's cursor will jump to the first occurence,
  • Disable interactive search by default so that when the search window is not present, all the keywords works normally (As opposed to before)

Partly fixes #565

Comment on lines +174 to +175
gboolean search_equal_func_index(GtkTreeModel* model, gint column, const gchar* key, GtkTreeIter* iter,
gpointer search_data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reimplement the search equal function so that it will also compared with collapsed entries

@@ -125,6 +128,82 @@ static gboolean search_current_index(GtkTreeModel* model, GtkTreePath* UNUSED(pa
return FALSE;
}

static bool find_substring(const char* source_str, const char* search_str) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Find the search_str in source_str, as opposed to only match from the beginning of source_str

@@ -1203,6 +1203,8 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
gtk_tree_view_column_set_alignment(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 1), 1.0f);
gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), search_equal_func_index, treeview, NULL);
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(treeview), FALSE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disable interactive search by default, so that all the hotkeys (j, k, q...) are not consummed by the search function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Searching in index
1 participant