aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-06 08:24:13 +0800
committerGitHub <noreply@github.com>2025-03-06 08:24:13 +0800
commit1a35eb9b568e1d916cf86dfb27c723e788254923 (patch)
tree8ee25036a082a444d3f9af5df8856c194eb5c60e /src
parenta261f602a067c7cb4de39fa6330053c08dcfd5e5 (diff)
downloadrneovim-1a35eb9b568e1d916cf86dfb27c723e788254923.tar.gz
rneovim-1a35eb9b568e1d916cf86dfb27c723e788254923.tar.bz2
rneovim-1a35eb9b568e1d916cf86dfb27c723e788254923.zip
vim-patch:9.1.1175: inconsistent behaviour with exclusive selection and motion commands (#32745)
Problem: inconsistent behaviour with exclusive selection and motion commands (aidancz) Solution: adjust cursor position when selection is exclusive (Jim Zhou) fixes: vim/vim#16278 closes: vim/vim#16784 https://github.com/vim/vim/commit/c8cce711dde2d8abcf0929b3b12c4bfc5547a89d Co-authored-by: Jim Zhou <jimzhouzzy@gmail.com> Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/normal.c24
-rw-r--r--src/nvim/textobject.c8
3 files changed, 28 insertions, 6 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index e0bbba3d68..15152bc1a4 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -464,6 +464,8 @@ EXTERN bool VIsual_active INIT( = false);
EXTERN bool VIsual_select INIT( = false);
/// Register name for Select mode
EXTERN int VIsual_select_reg INIT( = 0);
+/// Whether incremented cursor during exclusive selection
+EXTERN bool VIsual_select_exclu_adj INIT( = false);
/// Restart Select mode when next cmd finished
EXTERN int restart_VIsual_select INIT( = 0);
/// Whether to restart the selection after a Select-mode mapping or menu.
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 44e48e9e72..83ab0d5c24 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -1524,6 +1524,7 @@ static void set_vcount_ca(cmdarg_T *cap, bool *set_prevcount)
/// do_pending_operator().
void end_visual_mode(void)
{
+ VIsual_select_exclu_adj = false;
VIsual_active = false;
setmouse();
mouse_dragging = 0;
@@ -4035,17 +4036,24 @@ static int normal_search(cmdarg_T *cap, int dir, char *pat, size_t patlen, int o
/// cap->nchar is NUL for ',' and ';' (repeat the search)
static void nv_csearch(cmdarg_T *cap)
{
- bool t_cmd;
+ bool cursor_dec = false;
- if (cap->cmdchar == 't' || cap->cmdchar == 'T') {
- t_cmd = true;
- } else {
- t_cmd = false;
+ // If adjusted cursor position previously, unadjust it.
+ if (*p_sel == 'e' && VIsual_active && VIsual_mode == 'v'
+ && VIsual_select_exclu_adj) {
+ unadjust_for_sel();
+ cursor_dec = true;
}
+ bool t_cmd = cap->cmdchar == 't' || cap->cmdchar == 'T';
+
cap->oap->motion_type = kMTCharWise;
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == false) {
clearopbeep(cap->oap);
+ // Revert unadjust when failed.
+ if (cursor_dec) {
+ adjust_for_sel(cap);
+ }
return;
}
@@ -5054,6 +5062,8 @@ static void nv_visual(cmdarg_T *cap)
n_start_visual_mode(cap->cmdchar);
if (VIsual_mode != 'V' && *p_sel == 'e') {
cap->count1++; // include one more char
+ } else {
+ VIsual_select_exclu_adj = false;
}
if (cap->count0 > 0 && --cap->count1 > 0) {
// With a count select that many characters or lines.
@@ -6021,6 +6031,7 @@ static void adjust_for_sel(cmdarg_T *cap)
&& gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor)) {
inc_cursor();
cap->oap->inclusive = false;
+ VIsual_select_exclu_adj = true;
}
}
@@ -6042,7 +6053,7 @@ bool unadjust_for_sel(void)
/// @return true when backed up to the previous line.
bool unadjust_for_sel_inner(pos_T *pp)
{
- colnr_T cs, ce;
+ VIsual_select_exclu_adj = false;
if (pp->coladd > 0) {
pp->coladd--;
@@ -6050,6 +6061,7 @@ bool unadjust_for_sel_inner(pos_T *pp)
pp->col--;
mark_mb_adjustpos(curbuf, pp);
if (virtual_active(curwin)) {
+ colnr_T cs, ce;
getvcol(curwin, pp, &cs, NULL, &ce);
pp->coladd = ce - cs;
}
diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c
index e3b3bba7c1..fda8b45e21 100644
--- a/src/nvim/textobject.c
+++ b/src/nvim/textobject.c
@@ -19,6 +19,7 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/move.h"
+#include "nvim/normal.h"
#include "nvim/option_vars.h"
#include "nvim/pos_defs.h"
#include "nvim/search.h"
@@ -427,6 +428,13 @@ int end_word(int count, bool bigword, bool stop, bool empty)
curwin->w_cursor.coladd = 0;
cls_bigword = bigword;
+
+ // If adjusted cursor position previously, unadjust it.
+ if (*p_sel == 'e' && VIsual_active && VIsual_mode == 'v'
+ && VIsual_select_exclu_adj) {
+ unadjust_for_sel();
+ }
+
while (--count >= 0) {
// When inside a range of folded lines, move to the last char of the
// last line.