Blob Blame History Raw
To: vim-dev@vim.org
Subject: Patch 7.1.158 (extra)
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.1.158 (extra)
Problem:    Win32 console: When 'encoding' is "utf-8" and typing Alt-y the
            result is wrong.  Win32 GUI: Alt-y results in "u" when 'encoding'
            is "cp1250" (Lukas Cerman)
Solution:   For utf-8 don't set the 7th bit in a byte, convert to the correct
            byte sequence.  For cp1250, when conversion to 'encoding' results
            in the 7th bit not set, set the 7th bit after conversion.
Files:      src/os_win32.c, src/gui_w48.c


*** ../vim-7.1.157/src/os_win32.c	Mon Oct  1 20:33:45 2007
--- src/os_win32.c	Sat Oct 27 17:35:04 2007
***************
*** 1521,1527 ****
--- 1521,1532 ----
  #endif
  		   )
  		{
+ #ifdef FEAT_MBYTE
+ 		    n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80,
+ 						    typeahead + typeaheadlen);
+ #else
  		    typeahead[typeaheadlen] |= 0x80;
+ #endif
  		    modifiers &= ~MOD_MASK_ALT;
  		}
  
*** ../vim-7.1.157/src/gui_w48.c	Sun Sep 30 14:00:41 2007
--- src/gui_w48.c	Mon Oct 29 20:00:25 2007
***************
*** 486,495 ****
  
  /*
   * Convert Unicode character "ch" to bytes in "string[slen]".
   * Return the length.
   */
      static int
! char_to_string(int ch, char_u *string, int slen)
  {
      int		len;
      int		i;
--- 486,496 ----
  
  /*
   * Convert Unicode character "ch" to bytes in "string[slen]".
+  * When "had_alt" is TRUE the ALT key was included in "ch".
   * Return the length.
   */
      static int
! char_to_string(int ch, char_u *string, int slen, int had_alt)
  {
      int		len;
      int		i;
***************
*** 522,529 ****
--- 523,544 ----
  	 * "enc_codepage" is non-zero use the standard Win32 function,
  	 * otherwise use our own conversion function (e.g., for UTF-8). */
  	if (enc_codepage > 0)
+ 	{
  	    len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
  						       string, slen, 0, NULL);
+ 	    /* If we had included the ALT key into the character but now the
+ 	     * upper bit is no longer set, that probably means the conversion
+ 	     * failed.  Convert the original character and set the upper bit
+ 	     * afterwards. */
+ 	    if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80)
+ 	    {
+ 		wstring[0] = ch & 0x7f;
+ 		len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
+ 						       string, slen, 0, NULL);
+ 		if (len == 1) /* safety check */
+ 		    string[0] |= 0x80;
+ 	    }
+ 	}
  	else
  	{
  	    len = 1;
***************
*** 573,579 ****
      char_u	string[40];
      int		len = 0;
  
!     len = char_to_string(ch, string, 40);
      if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
      {
  	trash_input_buf();
--- 588,594 ----
      char_u	string[40];
      int		len = 0;
  
!     len = char_to_string(ch, string, 40, FALSE);
      if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
      {
  	trash_input_buf();
***************
*** 640,646 ****
      {
  	/* Although the documentation isn't clear about it, we assume "ch" is
  	 * a Unicode character. */
! 	len += char_to_string(ch, string + len, 40 - len);
      }
  
      add_to_input_buf(string, len);
--- 655,661 ----
      {
  	/* Although the documentation isn't clear about it, we assume "ch" is
  	 * a Unicode character. */
! 	len += char_to_string(ch, string + len, 40 - len, TRUE);
      }
  
      add_to_input_buf(string, len);
***************
*** 1775,1781 ****
  		    int	len;
  
  		    /* Handle "key" as a Unicode character. */
! 		    len = char_to_string(key, string, 40);
  		    add_to_input_buf(string, len);
  		}
  		break;
--- 1790,1796 ----
  		    int	len;
  
  		    /* Handle "key" as a Unicode character. */
! 		    len = char_to_string(key, string, 40, FALSE);
  		    add_to_input_buf(string, len);
  		}
  		break;
*** ../vim-7.1.157/src/version.c	Tue Nov 20 12:30:31 2007
--- src/version.c	Tue Nov 20 17:19:18 2007
***************
*** 668,669 ****
--- 668,671 ----
  {   /* Add new patch number below this line */
+ /**/
+     158,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
123. You ask the car dealer to install an extra cigarette lighter
     on your new car to power your notebook.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///