mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	Refactor vim_feedkeys and f_feedkeys
- To clean up the mix between feedkeys and replace_termcodes the vim_feedkeys API function now does the same thing as the vimscript feedkeys() function - The original f_feedkeys() function now calls the vim_feedkeys() function from the API
This commit is contained in:
		 Rui Abreu Ferreira
					Rui Abreu Ferreira
				
			
				
					committed by
					
						 Thiago de Arruda
						Thiago de Arruda
					
				
			
			
				
	
			
			
			 Thiago de Arruda
						Thiago de Arruda
					
				
			
						parent
						
							d8beb77b1b
						
					
				
				
					commit
					1dea4044e7
				
			| @@ -54,55 +54,34 @@ void vim_command(String str, Error *err) | |||||||
| /// Pass input keys to Neovim | /// Pass input keys to Neovim | ||||||
| /// | /// | ||||||
| /// @param keys to be typed | /// @param keys to be typed | ||||||
| /// @param replace_tcodes If true replace special keys such as <CR> or <Leader> | /// @param mode specifies the mapping options | ||||||
| ///           for compatibility with Vim --remote-send expressions | /// @see feedkeys() | ||||||
| /// @param remap If True remap keys | void vim_feedkeys(String keys, String mode) | ||||||
| /// @param typed Handle keys as if typed; otherwise they are handled as |  | ||||||
| ///           if coming from a mapping.  This matters for undo, |  | ||||||
| ///           opening folds, etc. |  | ||||||
| void vim_feedkeys(String keys, Boolean replace_tcodes, Boolean remap, |  | ||||||
|                 Boolean typed, Error *err) |  | ||||||
| { | { | ||||||
|   char *ptr = NULL; |   bool remap = true; | ||||||
|   char *cpo_save = (char *)p_cpo; |   bool typed = false; | ||||||
|  |  | ||||||
|   if (replace_tcodes) { |   if (keys.size == 0) { | ||||||
|     // Set 'cpoptions' the way we want it. |     return; | ||||||
|     //    B set - backslashes are *not* treated specially |  | ||||||
|     //    k set - keycodes are *not* reverse-engineered |  | ||||||
|     //    < unset - <Key> sequences *are* interpreted |  | ||||||
|     //  The last but one parameter of replace_termcodes() is TRUE so that the |  | ||||||
|     //  <lt> sequence is recognised - needed for a real backslash. |  | ||||||
|     p_cpo = (char_u *)"Bk"; |  | ||||||
|     replace_termcodes((char_u *)keys.data, (char_u **)&ptr, false, true, true); |  | ||||||
|     p_cpo = (char_u *)cpo_save; |  | ||||||
|   } else { |  | ||||||
|     ptr = keys.data; |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (ptr == NULL) { |   for (size_t i = 0; i < mode.size; ++i) { | ||||||
|     set_api_error("Failed to eval expression", err); |     switch (mode.data[i]) { | ||||||
|   } else { |     case 'n': remap = false; break; | ||||||
|     // Add the string to the input stream. |     case 'm': remap = true; break; | ||||||
|     // Can't use add_to_input_buf() here, we now have K_SPECIAL bytes. |     case 't': typed = true; break; | ||||||
|     // |  | ||||||
|     // First clear typed characters from the typeahead buffer, there could |  | ||||||
|     // be half a mapping there.  Then append to the existing string, so |  | ||||||
|     // that multiple commands from a client are concatenated. |  | ||||||
|     if (typebuf.tb_maplen < typebuf.tb_len) { |  | ||||||
|         del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen); |  | ||||||
|     } |     } | ||||||
|     (void)ins_typebuf((char_u *)ptr, (remap ? REMAP_YES : REMAP_NONE), |   } | ||||||
|                     typebuf.tb_len, !typed, false); |  | ||||||
|  |  | ||||||
|     // Let input_available() know we inserted text in the typeahead |   /* Need to escape K_SPECIAL and CSI before putting the string in the | ||||||
|     // buffer. */ |    * typeahead buffer. */ | ||||||
|  |   char *keys_esc = (char *)vim_strsave_escape_csi((char_u *)keys.data); | ||||||
|  |   ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE), | ||||||
|  |       typebuf.tb_len, !typed, false); | ||||||
|  |   free(keys_esc); | ||||||
|  |  | ||||||
|  |   if (vgetc_busy) | ||||||
|     typebuf_was_filled = true; |     typebuf_was_filled = true; | ||||||
|  |  | ||||||
|     if (replace_tcodes) { |  | ||||||
|       free(ptr); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Evaluates the expression str using the vim internal expression | /// Evaluates the expression str using the vim internal expression | ||||||
|   | |||||||
| @@ -83,7 +83,7 @@ | |||||||
| #include "nvim/os/time.h" | #include "nvim/os/time.h" | ||||||
| #include "nvim/os/channel.h" | #include "nvim/os/channel.h" | ||||||
| #include "nvim/api/private/helpers.h" | #include "nvim/api/private/helpers.h" | ||||||
| #include "nvim/api/private/defs.h" | #include "nvim/api/vim.h" | ||||||
| #include "nvim/os/msgpack_rpc_helpers.h" | #include "nvim/os/msgpack_rpc_helpers.h" | ||||||
| #include "nvim/os/dl.h" | #include "nvim/os/dl.h" | ||||||
| #include "nvim/os/provider.h" | #include "nvim/os/provider.h" | ||||||
| @@ -8280,11 +8280,8 @@ static void f_extend(typval_T *argvars, typval_T *rettv) | |||||||
|  */ |  */ | ||||||
| static void f_feedkeys(typval_T *argvars, typval_T *rettv) | static void f_feedkeys(typval_T *argvars, typval_T *rettv) | ||||||
| { | { | ||||||
|   int remap = TRUE; |   char_u      *keys, *flags = NULL; | ||||||
|   char_u      *keys, *flags; |  | ||||||
|   char_u nbuf[NUMBUFLEN]; |   char_u nbuf[NUMBUFLEN]; | ||||||
|   int typed = FALSE; |  | ||||||
|   char_u      *keys_esc; |  | ||||||
|  |  | ||||||
|   /* This is not allowed in the sandbox.  If the commands would still be |   /* This is not allowed in the sandbox.  If the commands would still be | ||||||
|    * executed in the sandbox it would be OK, but it probably happens later, |    * executed in the sandbox it would be OK, but it probably happens later, | ||||||
| @@ -8296,23 +8293,10 @@ static void f_feedkeys(typval_T *argvars, typval_T *rettv) | |||||||
|   if (*keys != NUL) { |   if (*keys != NUL) { | ||||||
|     if (argvars[1].v_type != VAR_UNKNOWN) { |     if (argvars[1].v_type != VAR_UNKNOWN) { | ||||||
|       flags = get_tv_string_buf(&argvars[1], nbuf); |       flags = get_tv_string_buf(&argvars[1], nbuf); | ||||||
|       for (; *flags != NUL; ++flags) { |  | ||||||
|         switch (*flags) { |  | ||||||
|         case 'n': remap = FALSE; break; |  | ||||||
|         case 'm': remap = TRUE; break; |  | ||||||
|         case 't': typed = TRUE; break; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* Need to escape K_SPECIAL and CSI before putting the string in the |     vim_feedkeys(cstr_as_string((char *)keys), | ||||||
|      * typeahead buffer. */ | 		    cstr_as_string((char *)flags)); | ||||||
|     keys_esc = vim_strsave_escape_csi(keys); |  | ||||||
|     ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE), |  | ||||||
|         typebuf.tb_len, !typed, FALSE); |  | ||||||
|     free(keys_esc); |  | ||||||
|     if (vgetc_busy) |  | ||||||
|       typebuf_was_filled = TRUE; |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user