Hi krzysztof!

On Di, 17 Apr 2012, krzysztof cierpisz wrote:

> 
> 
> On Apr 17, 8:40 am, "Christian Brabandt" <cbli...@256bit.org> wrote:
> > On Tue, April 17, 2012 08:33, krzysztof cierpisz wrote:
> > > I am on Ubuntu and using Gnome Terminal 2.30.2
> >
> > > 1. I copied following word "zużycia" from my Chrome browser (encoding
> > > UTF-8) to clipboard.
> >
> > > 2. then I pasted into my Vim (7.3.315) and pasted word appeared as
> > > "zużycia"
> > > :set enc => utf-8
> >
> > > 3. when I paste the same word from 1. into Terminal (without opened
> > > Vim) the word appears correct: "zużycia"
> >
> > > 4. when I copy the pasted "zużycia" from the Terminal and then open
> > > Vim and paste it there all is fine and pasted word appears as
> > > "zużycia"
> >
> > > What can I check to find out the reason why direct copy from Chrome to
> > > Vim is not working properly?
> >
> > That is a known issue, that is in the todo list.
> > :h todo and search for chrome
> >
> 
> ok, thanks for the info, did not know that.

Here is an experimental patch, that seems to fix this issue for me. 
Please, anybody who has problems with pasting garbled characters, try 
the attached patch.

The idea is simply, when compound_text atom is used, to also try to 
receive the text in utf8 encoding, if iso8859 encoding isn't valid, 
although it seems compound_text should only be valid in iso8859 
encodings and alike. I guess, it is more a workaround, but if it works, 
we get correct results and if it fails, we still have the same issue as 
we do now ;)

Disclaimer: I almost know nothing about X11 client communication, but 
this patch seems to fix it for me. 

With this patch enabled, I could successfully paste "zużycia" from 
Chrome browser using clipboard and primary selection in both an 
mbyte-enabled vim and a vim without mbyte feature.

I also tried from the previously mentioned threads, but couldn't 
reproduce the issue from back then.

regards,
Christian

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/ui.c b/src/ui.c
--- a/src/ui.c
+++ b/src/ui.c
@@ -2089,20 +2089,35 @@
 	XTextProperty	text_prop;
 	int		n_text = 0;
 	int		status;
+	int             j;
 
 	text_prop.value = (unsigned char *)value;
 	text_prop.encoding = *type;
 	text_prop.format = *format;
 	text_prop.nitems = len;
-	status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop,
-							 &text_list, &n_text);
-	if (status != Success || n_text < 1)
+	for (j=0; j<2; j++)
 	{
-	    *(int *)success = FALSE;
-	    return;
+	    if (j==0)
+		status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop,
+							&text_list, &n_text);
+	    else
+	      /* could be utf-8 encoded */
+		status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop,
+							&text_list, &n_text);
+	    if (j == 0 && (status != Success || n_text < 1))
+	      continue;
+	    else if (j==1 && (status != Success || n_text < 1))
+	    {
+		*(int *)success = FALSE;
+		return;
+	    }
+	    else
+	    {
+		p = (char_u *)text_list[0];
+		len = STRLEN(p);
+		break;
+	    }
 	}
-	p = (char_u *)text_list[0];
-	len = STRLEN(p);
     }
     clip_yank_selection(motion_type, p, (long)len, cbd);
 
@@ -2147,12 +2162,16 @@
 #endif
 	    case 3:  type = compound_text_atom; break;
 	    case 4:  type = text_atom;		break;
-	    default: type = XA_STRING;
+	    case 5:  type = XA_STRING;
+	    default: type = 0;
 	}
 #ifdef FEAT_MBYTE
 	if (type == utf8_atom && !enc_utf8)
 	    /* Only request utf-8 when 'encoding' is utf8. */
 	    continue;
+#else
+	if (type == 0)
+	  continue;
 #endif
 	success = MAYBE;
 	XtGetSelectionValue(myShell, cbd->sel_atom, type,

Reply via email to