gtkfilechooser: preserve location entry selection after typed folder changes

This commit is contained in:
Daemonratte 2026-05-28 11:00:41 +02:00
commit 2ccdfc445d

View file

@ -8890,6 +8890,20 @@ location_mode_set (GtkFileChooserDefault *impl,
impl->location_mode = new_mode;
}
static gboolean
location_select_current_folder_text_idle (gpointer data)
{
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
if (impl->location_entry &&
(impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) &&
impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
return FALSE;
}
static void
location_set_current_folder_text (GtkFileChooserDefault *impl,
gboolean select_text)
@ -8913,7 +8927,18 @@ location_set_current_folder_text (GtkFileChooserDefault *impl,
gtk_entry_set_text (GTK_ENTRY (impl->location_entry), path);
if (select_text)
gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
{
gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
/* Folder changes from typed paths can trigger entry/completion updates
* after the text was set. Queue a final selection so keyboard-entered
* folders keep the full path selected.
*/
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
location_select_current_folder_text_idle,
g_object_ref (impl),
g_object_unref);
}
else
gtk_editable_set_position (GTK_EDITABLE (impl->location_entry), -1);
@ -12506,12 +12531,12 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
impl->current_folder);
if (data->clear_entry)
if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) &&
impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
location_set_current_folder_text (impl, data->clear_entry);
else if (data->clear_entry)
gtk_entry_set_text (GTK_ENTRY (impl->location_entry), "");
else if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) &&
impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
location_set_current_folder_text (impl, FALSE);
}
/* Create a new list model. This is slightly evil; we store the result value