Hello Jianzhong,

> When using ctrl-p to load uri from clipboard, it's better to strip the
> leading whitespace.

I'm not sure it is.

> For example, to select/copy a uri  from text in terminal and paste to
> surf, currently it need to be very careful not to include any
> whitespace before the uri.

Yes, yo do.

> It's easy for keyboard selection, but for mouse selection, precise
> positioning is a little bit difficult.

I'd suggest you manage this outside of surf, either by training your
mouse skills, or by stripping those leading whitespaces in your
selecting application.

> patch as below:
> 
> diff -Nur surf/surf.c surfn/surf.c
> --- surf/surf.c 2017-10-17 13:58:00.636699137 +0800
> +++ surfn/surf.c    2017-10-17 13:58:29.440798516 +0800
> @@ -1707,7 +1707,8 @@
>  void
>  pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
>  {
> -   Arg a = {.v = text };
> +   char *trimed = g_strstrip(g_strdup(text));
> +   Arg a = {.v = trimed };
>     if (text)
>         loaduri((Client *) d, &a);
>  }

As other stated, you're allocating a new string there whithout ever
releasing it which is wrong.

I'd suggest a simpler approach like this :

diff --git a/surf.c b/surf.c
index 0f8b9c9..8a40a3b 100644
--- a/surf.c
+++ b/surf.c
@@ -1685,9 +1685,14 @@ destroywin(GtkWidget* w, Client *c)
 void
 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
 {
-       Arg a = {.v = text };
-       if (text)
+       Arg a;
+
+       if (text) {
+               for (; *text && (*text == ' ' || *text == '\t'); ++text)
+                       ;
+               a.v = text;
                loaduri((Client *) d, &a);
+       }
 }

 void

---

I'm open to discuss this further though if more people complain about
it, thanks for your interest in surf!

-- Quentin

Reply via email to