Re: [dev] [surf] [patch] strip uri leading whitespace when ctrl-p

From: 黄建忠 <jianzhong.huang_AT_i-soft.com.cn>
Date: Thu, 19 Oct 2017 16:40:22 +0800

在 2017年10月19日 16:00, Hiltjo Posthuma 写道:
> On Thu, Oct 19, 2017 at 12:47:41PM +0800, 黄建忠 wrote:
>> When using ctrl-p to load uri from clipboard, it's better to strip the
>> leading whitespace.
>>
>> 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.
>>
>> It's easy for keyboard selection, but for mouse selection, precise
>> positioning is a little bit difficult.
>>
>>
>> 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
>> _AT_@ -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);
>>  }
>>
>>
>> --
>> Huang JianZhong
>>
>>
> Hey,
>
> Doesn't this leak memory?
>
> (NOTE: for single-use programs it is ok to not free memory at the end).
>
Tks, g_strdup need g_free, g_strstrip will not allocate new memory.

Maybe it should changed like this?

    if (text) {
        char *atext = g_strdup(text);
        char *trimed = g_strstrip(atext);
        Arg a = {.v = trimed };
            loaduri((Client *) d, &a);
        g_free(atext);
    }

-- 
Huang JianZhong
Received on Thu Oct 19 2017 - 10:40:22 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 19 2017 - 10:48:16 CEST