diff options
| author | Přemysl Janouch <p@janouch.name> | 2018-06-30 13:23:30 +0200 | 
|---|---|---|
| committer | Přemysl Janouch <p@janouch.name> | 2018-06-30 13:23:30 +0200 | 
| commit | b0d3b2dcb5c02fedb0f4d95e8337f7829015a7bd (patch) | |
| tree | 1cfe728da610c3e691d1114a2f7926d25e09b451 | |
| parent | 4b191cce3d599a16ac5cb0e2bfe93ede3a144539 (diff) | |
| download | tdv-b0d3b2dcb5c02fedb0f4d95e8337f7829015a7bd.tar.gz tdv-b0d3b2dcb5c02fedb0f4d95e8337f7829015a7bd.tar.xz tdv-b0d3b2dcb5c02fedb0f4d95e8337f7829015a7bd.zip | |
Strip whitespace from clipboard contents
| -rw-r--r-- | src/sdtui.c | 18 | 
1 files changed, 13 insertions, 5 deletions
| diff --git a/src/sdtui.c b/src/sdtui.c index d8bed9c..5ccef5d 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -1905,10 +1905,10 @@ on_terminated (gpointer user_data)  #ifdef WITH_GTK  static void -app_set_input (Application *self, const gchar *input) +app_set_input (Application *self, const gchar *text, gsize text_len)  {  	glong size; -	gunichar *output = g_utf8_to_ucs4 (input, -1, NULL, &size, NULL); +	gunichar *output = g_utf8_to_ucs4 (text, text_len, NULL, &size, NULL);  	// XXX: signal invalid data?  	if (!output) @@ -1943,12 +1943,20 @@ on_selection_text_received (G_GNUC_UNUSED GtkClipboard *clipboard,  	if (text)  	{ -		if (app->selection_contents && !strcmp (app->selection_contents, text)) +		// Strip ASCII whitespace: this is compatible with UTF-8 +		while (g_ascii_isspace (*text)) +			text++; +		gsize text_len = strlen (text); +		while (text_len && g_ascii_isspace (text[text_len - 1])) +			text_len--; + +		if (app->selection_contents && +			!strncmp (app->selection_contents, text, text_len))  			return;  		g_free (app->selection_contents); -		app->selection_contents = g_strdup (text); -		app_set_input (app, text); +		app->selection_contents = g_strndup (text, text_len); +		app_set_input (app, text, text_len);  	}  	else if (app->selection_contents)  	{ | 
