summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Westman <james@flyingpimonster.net>2020-12-31 19:59:18 -0600
committerAntónio Fernandes <antoniof@gnome.org>2021-02-12 23:47:26 +0000
commitdbd5be23a6645188f942ee99a22f91966ae83260 (patch)
tree8c0358e650f76116dddbf4251854827bf00f8590
parent4fad42b7b478946ba9d0d72107b6970468827647 (diff)
downloadnautilus-dbd5be23a6645188f942ee99a22f91966ae83260.tar.gz
location-entry: Use relative completions for relative paths
If the user enters a relative path, we get absolute paths as in the completion popover, which is quite jarring and makes it less useful. Instead, truncate the prefix, such that the completions dropdown text aligns with the entry text.
-rw-r--r--src/nautilus-location-entry.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c
index 7d14a9dc3..f09611f19 100644
--- a/src/nautilus-location-entry.c
+++ b/src/nautilus-location-entry.c
@@ -363,11 +363,14 @@ update_completions_store (gpointer callback_data)
GtkEditable *editable;
g_autofree char *absolute_location = NULL;
g_autofree char *user_location = NULL;
+ gboolean is_relative = FALSE;
int start_sel;
g_autofree char *uri_scheme = NULL;
g_auto (GStrv) completions = NULL;
+ char *completion;
int i;
GtkTreeIter iter;
+ int current_dir_strlen;
entry = NAUTILUS_LOCATION_ENTRY (callback_data);
priv = nautilus_location_entry_get_instance_private (entry);
@@ -390,6 +393,7 @@ update_completions_store (gpointer callback_data)
if (!g_path_is_absolute (user_location) && uri_scheme == NULL && user_location[0] != '~')
{
+ is_relative = TRUE;
absolute_location = g_build_filename (priv->current_directory, user_location, NULL);
}
else
@@ -402,10 +406,25 @@ update_completions_store (gpointer callback_data)
/* populate the completions model */
gtk_list_store_clear (priv->completions_store);
+ current_dir_strlen = strlen (priv->current_directory);
for (i = 0; completions[i] != NULL; i++)
{
+ completion = completions[i];
+
+ if (is_relative && strlen (completion) >= current_dir_strlen)
+ {
+ /* For relative paths, we need to strip the current directory
+ * (and the trailing slash) so the completions will match what's
+ * in the text entry */
+ completion += current_dir_strlen;
+ if (G_IS_DIR_SEPARATOR (completion[0]))
+ {
+ completion++;
+ }
+ }
+
gtk_list_store_append (priv->completions_store, &iter);
- gtk_list_store_set (priv->completions_store, &iter, 0, completions[i], -1);
+ gtk_list_store_set (priv->completions_store, &iter, 0, completion, -1);
}
/* refilter the completions dropdown */