mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 13:38:34 +00:00
Define special key for asynchronous events
K_EVENT/KE_EVENT are used to signal any loop that reads user input(scattered across normal.c edit.c , ex_getln.c and message.c) of asynchronous events that were not initiated by the user. Representing non-user asynchronous events as special keys has the following advantages: - We reuse the normal vim redrawing code. As far as the rest of the code in edit.c/normal.c is concerned, it's just the user pressing another key. - Assume less about vim tolerance for "out-of-band" modifications to its internal state. - We still have a very complex codebase and it's hard to predict what bugs may be introduced by these changes. With this we implement asynchronicity in a way that will be more "natural" to the editor and has less chance of causing unpredictable behavior. As the code is refactored, we will be able to treat user input as an 'event type' and not the other way around(With this we are treating arbitrary events as a special case of user input).
This commit is contained in:
@@ -164,6 +164,7 @@ static void map_free(mapblock_T **);
|
||||
static void validate_maphash(void);
|
||||
static void showmap(mapblock_T *mp, int local);
|
||||
static char_u *eval_map_expr(char_u *str, int c);
|
||||
static bool is_user_input(int k);
|
||||
|
||||
/*
|
||||
* Free and clear a buffer.
|
||||
@@ -2552,11 +2553,10 @@ fix_input_buffer (
|
||||
* Don't replace K_SPECIAL when reading a script file.
|
||||
*/
|
||||
for (i = len; --i >= 0; ++p) {
|
||||
if (p[0] == NUL || (p[0] == K_SPECIAL && !script
|
||||
/* timeout may generate K_CURSORHOLD */
|
||||
&& (i < 2 || p[1] != KS_EXTRA || p[2] !=
|
||||
(int)KE_CURSORHOLD)
|
||||
)) {
|
||||
if (p[0] == NUL
|
||||
|| (p[0] == K_SPECIAL
|
||||
&& !script
|
||||
&& (i < 2 || p[1] != KS_EXTRA || is_user_input(p[2])))) {
|
||||
memmove(p + 3, p + 1, (size_t)i);
|
||||
p[2] = K_THIRD(p[0]);
|
||||
p[1] = K_SECOND(p[0]);
|
||||
@@ -3816,6 +3816,11 @@ eval_map_expr (
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool is_user_input(int k)
|
||||
{
|
||||
return k != (int)KE_EVENT && k != (int)KE_CURSORHOLD;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy "p" to allocated memory, escaping K_SPECIAL and CSI so that the result
|
||||
* can be put in the typeahead buffer.
|
||||
|
Reference in New Issue
Block a user