Skip to content

Commit

Permalink
List dialog should scroll to an initially selected item if necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalquark committed Mar 1, 2025
1 parent f415cb2 commit 4912f06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/textadept_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,9 @@ static int visible(GtkTreeModel *model, GtkTreeIter *iter, void *treeview) {
static void select_nth_item(GtkTreeView *view, int n) {
GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
if (gtk_tree_selection_count_selected_rows(selection) > 0) return; // already selected
GtkTreeIter iter;
if (!gtk_tree_model_get_iter_first(gtk_tree_view_get_model(view), &iter)) return;
for (int i = 1; i < n; i++) gtk_tree_model_iter_next(gtk_tree_view_get_model(view), &iter);
gtk_tree_selection_select_iter(selection, &iter);
GtkTreePath *path = gtk_tree_path_new_from_indices(n - 1, -1);
gtk_tree_selection_select_path(selection, path);
gtk_tree_view_scroll_to_cell(view, path, NULL, false, 0, 0);
}

// Signal for showing and hiding list values/rows depending on the current search key.
Expand Down
7 changes: 4 additions & 3 deletions src/textadept_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,13 @@ int list_dialog(DialogOptions opts, lua_State *L) {
QString{text}.replace(QRegularExpression{"([^A-Za-z0-9_])"}, "\\\\1").replace("\\ ", ".*");
filter.setFilterRegularExpression(
QRegularExpression{re, QRegularExpression::CaseInsensitiveOption});
selection->select(
selection->setCurrentIndex(
filter.index(0, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
});
if (opts.text) lineEdit->setText(opts.text);
selection->select(
filter.index(opts.select - 1, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
auto index = filter.index(opts.select - 1, 0);
selection->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
if (opts.select) QTimer::singleShot(0, [&treeView, index]() { treeView->scrollTo(index); });
lineEdit->installEventFilter(new KeyForwarder{treeView, &dialog});
auto buttonBox = new QDialogButtonBox;
int buttonClicked = 1; // ok/accept by default
Expand Down

0 comments on commit 4912f06

Please sign in to comment.