commit f56d2b3c596218e503cad8f9bdb028bf780577a1
parent e1a3128ec4312f537479bbe4dcd789599ac054fc
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu, 27 Feb 2025 08:52:38 +0800
vim-patch:9.1.1152: Patch v9.1.1151 causes problems
Problem: Patch v9.1.1151 causes problems
Solution: partially revert it (John Marriott)
closes: vim/vim#16736
https://github.com/vim/vim/commit/18bacc811c30ba26405cadbeb79d9013d9885bb5
Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat:
2 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
@@ -155,8 +155,6 @@ static uint8_t noremapbuf_init[TYPELEN_INIT]; ///< initial typebuf.tb_noremap
static size_t last_recorded_len = 0; ///< number of last recorded chars
-static size_t last_get_recorded_len = 0; ///< length of the string returned from the
- ///< last call to get_recorded()
static size_t last_get_inserted_len = 0; ///< length of the string returned from the
///< last call to get_inserted()
@@ -230,7 +228,8 @@ static char *get_buffcont(buffheader_T *buffer, int dozero, size_t *len)
/// K_SPECIAL in the returned string is escaped.
char *get_recorded(void)
{
- char *p = get_buffcont(&recordbuff, true, &last_get_recorded_len);
+ size_t len;
+ char *p = get_buffcont(&recordbuff, true, &len);
if (p == NULL) {
return NULL;
}
@@ -239,28 +238,20 @@ char *get_recorded(void)
// Remove the characters that were added the last time, these must be the
// (possibly mapped) characters that stopped the recording.
- if (last_get_recorded_len >= last_recorded_len) {
- last_get_recorded_len -= last_recorded_len;
- p[last_get_recorded_len] = NUL;
+ if (len >= last_recorded_len) {
+ len -= last_recorded_len;
+ p[len] = NUL;
}
// When stopping recording from Insert mode with CTRL-O q, also remove the
// CTRL-O.
- if (last_get_recorded_len > 0 && restart_edit != 0
- && p[last_get_recorded_len - 1] == Ctrl_O) {
- last_get_recorded_len--;
- p[last_get_recorded_len] = NUL;
+ if (len > 0 && restart_edit != 0 && p[len - 1] == Ctrl_O) {
+ p[len - 1] = NUL;
}
return p;
}
-/// Return the length of string returned from the last call of get_recorded().
-size_t get_recorded_len(void)
-{
- return last_get_recorded_len;
-}
-
/// Return the contents of the redo buffer as a single string.
/// K_SPECIAL in the returned string is escaped.
char *get_inserted(void)
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
@@ -1039,7 +1039,7 @@ int do_record(int c)
// restore the current register name.
yankreg_T *old_y_previous = y_previous;
- retval = stuff_yank(regname, p, get_recorded_len());
+ retval = stuff_yank(regname, p);
y_previous = old_y_previous;
}
@@ -1051,7 +1051,7 @@ int do_record(int c)
/// uppercase). "p" must have been allocated.
///
/// @return FAIL for failure, OK otherwise
-static int stuff_yank(int regname, char *p, size_t plen)
+static int stuff_yank(int regname, char *p)
{
// check for read-only register
if (regname != 0 && !valid_yank_reg(regname, true)) {
@@ -1063,6 +1063,7 @@ static int stuff_yank(int regname, char *p, size_t plen)
return OK;
}
+ const size_t plen = strlen(p);
yankreg_T *reg = get_yank_register(regname, YREG_YANK);
if (is_append_register(regname) && reg->y_array != NULL) {
String *pp = &(reg->y_array[reg->y_size - 1]);