diff options
author | Josh Rahm <rahm@google.com> | 2022-08-18 14:02:13 -0600 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-08-18 14:02:13 -0600 |
commit | d45440a5e5424aa867ea0ba8dae7338f60065410 (patch) | |
tree | d685b8fcadb43a74203659d8d2fb84e4bbb0805b | |
parent | 234128e54154932d194f0ca3d09c86c9b756c390 (diff) | |
download | rneovim-d45440a5e5424aa867ea0ba8dae7338f60065410.tar.gz rneovim-d45440a5e5424aa867ea0ba8dae7338f60065410.tar.bz2 rneovim-d45440a5e5424aa867ea0ba8dae7338f60065410.zip |
Change a bit about how userreg work.
* The userreg function can now return a list. If a list is returned, the
yankreg will be set to kMTLineWise, and each element in the list will
become a line in the yankreg.
* Use tv_get_string to get strings from typevals.
* call tv_free on the tv sent to typval_to_yankreg to properly unref the
values.
-rw-r--r-- | src/nvim/edit.c | 2 | ||||
-rw-r--r-- | src/nvim/ops.c | 50 |
2 files changed, 32 insertions, 20 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 5861e4c52b..969e0af9f5 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -4082,11 +4082,13 @@ static void ins_ctrl_g(void) // Don't map the second key. This also prevents the mode message to be // deleted when ESC is hit. no_mapping++; + allow_keys++; c = plain_vgetc(); no_mapping--; allow_keys--; switch (c) { + // CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col case K_UP: case Ctrl_K: diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d18824f0c1..02faf438ea 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -868,23 +868,12 @@ static void typval_to_yankreg(yankreg_T* yankreg, typval_T* val) dict_T* dict; typval_T tv; size_t i; + size_t sz; free_register(yankreg); memset(yankreg, 0, sizeof(*yankreg)); switch (val->v_type) { - case VAR_STRING: - yankreg->y_type = kMTCharWise; - yankreg->y_size = 1; - - if (val->vval.v_string) { - yankreg->y_array = xcalloc(sizeof(char*), 1); - yankreg->y_array[0] = strdup(val->vval.v_string); - } else { - yankreg->y_array = NULL; - } - - break; case VAR_DICT: dict = val->vval.v_dict; @@ -909,11 +898,7 @@ static void typval_to_yankreg(yankreg_T* yankreg, typval_T* val) i = 0; TV_LIST_ITER_CONST(tv.vval.v_list, li, { - if (li->li_tv.v_type == VAR_STRING) { - yankreg->y_array[i] = strdup(li->li_tv.vval.v_string); - } else { - yankreg->y_array[i] = NULL; - } + yankreg->y_array[i] = strdup(tv_get_string(&li->li_tv)); ++ i; }); @@ -930,7 +915,29 @@ static void typval_to_yankreg(yankreg_T* yankreg, typval_T* val) } break; + case VAR_LIST: + yankreg->y_type = kMTLineWise; + sz = (size_t) tv_list_len(val->vval.v_list); + yankreg->y_array = xcalloc(sizeof(char*), sz); + yankreg->y_size = sz; + i = 0; + TV_LIST_ITER_CONST(val->vval.v_list, li, { + yankreg->y_array[i] = strdup(tv_get_string(&li->li_tv)); + i ++; + }); + break; + default: + yankreg->y_type = kMTCharWise; + yankreg->y_size = 1; + + if (val->vval.v_string) { + yankreg->y_array = xcalloc(sizeof(char*), 1); + yankreg->y_array[0] = strdup(tv_get_string(val)); + } else { + yankreg->y_array = NULL; + } + break; } @@ -944,12 +951,15 @@ static void copy_userreg(yankreg_T* into, int regname) return; - typval_T ret; - if (call_userreg_put((const char*) curbuf->b_p_urf, regname, &ret) == FAIL) { + typval_T* ret = xmalloc(sizeof(typval_T)); + + if (call_userreg_put((const char*) curbuf->b_p_urf, regname, ret) == FAIL) { return; } - typval_to_yankreg(into, &ret); + typval_to_yankreg(into, ret); + + tv_free(ret); } /// @return yankreg_T to use, according to the value of `regname`. |