]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0181: line('w0') moves cursor in terminal-normal mode v9.2.0181
authorichizok <gclient.gaap@gmail.com>
Mon, 16 Mar 2026 21:47:36 +0000 (21:47 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 16 Mar 2026 21:47:36 +0000 (21:47 +0000)
Problem:  line('w0') moves cursor in terminal-normal mode
          (Biebar, after v9.2.0127)
Solution: Check that the terminal is not in terminal-normal-mode
          (Ozaki Kiichi).

fixes:  #19717
closes: #19718

Signed-off-by: Ozaki Kiichi <gclient.gaap@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/eval.c
src/misc1.c
src/normal.c
src/option.c
src/proto/terminal.pro
src/terminal.c
src/testdir/test_terminal3.vim
src/version.c

index 7168b19dee02640ac852e7026aff82c8c7071b53..ba18a41597143308d20994e708d1023643d1e2e2 100644 (file)
@@ -6984,7 +6984,9 @@ var2fpos(
        if (name[1] == '0')             // "w0": first visible line
        {
 #ifdef FEAT_TERMINAL
-           if (bt_terminal(curwin->w_buffer) && curwin->w_buffer->b_term != NULL)
+           if (bt_terminal(curwin->w_buffer)
+                                   && curwin->w_buffer->b_term != NULL
+                                   && !term_in_normal_mode(curwin->w_buffer))
                may_move_terminal_to_buffer(curwin->w_buffer->b_term, TRUE);
 #endif
            update_topline();
@@ -6996,7 +6998,9 @@ var2fpos(
        else if (name[1] == '$')        // "w$": last visible line
        {
 #ifdef FEAT_TERMINAL
-           if (bt_terminal(curwin->w_buffer) && curwin->w_buffer->b_term != NULL)
+           if (bt_terminal(curwin->w_buffer)
+                                   && curwin->w_buffer->b_term != NULL
+                                   && !term_in_normal_mode(curwin->w_buffer))
                may_move_terminal_to_buffer(curwin->w_buffer->b_term, TRUE);
 #endif
            validate_botline();
index bc1d5b6b30f0f17fb0e446a2cb86d67fb0f9bf7f..ca913f930a1618ae2e2a3fb61c0364333a9b80fe 100644 (file)
@@ -772,7 +772,7 @@ get_mode(char_u *buf)
            buf[i++] = restart_edit;
        }
 # ifdef FEAT_TERMINAL
-       else if (term_in_normal_mode())
+       else if (term_in_normal_mode(curbuf))
            buf[i++] = 't';
 # endif
     }
index e6923c0bc2cc31ba52fae63a65c60158747cbb09..a9b01821d47db0b5cee97f715935c970c3585a55 100644 (file)
@@ -6985,7 +6985,7 @@ nv_edit(cmdarg_T *cap)
     if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I'))
     {
 #ifdef FEAT_TERMINAL
-       if (term_in_normal_mode())
+       if (term_in_normal_mode(curbuf))
        {
            end_visual_mode();
            clearop(cap->oap);
@@ -7003,7 +7003,7 @@ nv_edit(cmdarg_T *cap)
        nv_object(cap);
     }
 #ifdef FEAT_TERMINAL
-    else if (term_in_normal_mode())
+    else if (term_in_normal_mode(curbuf))
     {
        clearop(cap->oap);
        term_enter_job_mode();
index 2228f90e3840bed28612a2226778469afa985436..60af0903372040a7a5d16da0b6fbaf4e70ace7a8 100644 (file)
@@ -3854,7 +3854,7 @@ did_set_modifiable(optset_T *args UNUSED)
 
 #ifdef FEAT_TERMINAL
     // Cannot set 'modifiable' when in Terminal mode.
-    if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
+    if (curbuf->b_p_ma && (term_in_normal_mode(curbuf) || (bt_terminal(curbuf)
                    && curbuf->b_term != NULL && !term_is_finished(curbuf))))
     {
        curbuf->b_p_ma = FALSE;
index c042df545e95f2e7d0cfb2b0bc3ed8bbfeaa89dc..6429ffadd5a4503fa09f366e48f108ceeb6cb02a 100644 (file)
@@ -15,7 +15,7 @@ int term_confirm_stop(buf_T *buf);
 int term_try_stop_job(buf_T *buf);
 void may_move_terminal_to_buffer(term_T *term, int redraw);
 int term_check_timers(int next_due_arg, proftime_T *now);
-int term_in_normal_mode(void);
+int term_in_normal_mode(buf_T *buf);
 void term_enter_job_mode(void);
 void check_no_reduce_keys(void);
 int send_keys_to_term(term_T *term, int c, int modmask, int typed);
index 3d0c7ea995ffaefb142e9aeb7118d835bf2c28e9..68b712b1865c730b4cf8c8f7f6f2ff5c1ea75d10 100644 (file)
@@ -2302,9 +2302,9 @@ term_enter_normal_mode(void)
  * Terminal-Normal mode.
  */
     int
-term_in_normal_mode(void)
+term_in_normal_mode(buf_T *buf)
 {
-    term_T *term = curbuf->b_term;
+    term_T *term = buf->b_term;
 
     return term != NULL && term->tl_normal_mode;
 }
index c8825917e935e02adc05bcc8ed8327d924af7173..7cf727e49cd64335bbe818f5671491f2ebd99886 100644 (file)
@@ -1202,6 +1202,14 @@ func Test_term_getpos()
   call assert_equal(13, str2nr(result[1]) - str2nr(result[0]))
   call assert_true(str2nr(result[0]) > 1)
 
+  " Regression: line('w0') and line('w$') must not move cursor position
+  call term_sendkeys(buf, "gg")
+  call term_sendkeys(buf, ":call line('w0')\<cr>")
+  call term_sendkeys(buf, ":call line('w$')\<cr>")
+  call term_wait(buf)
+  call WaitForAssert({-> assert_match("for i in", term_getline(buf, 1))})
+  call WaitForAssert({-> assert_match("line12", term_getline(buf, 13))})
+
   call StopVimInTerminal(buf)
   " this crashed
   new
index 8889f69af9c31a8313fd2c723a5c75c7e8cd31d9..9164ae0a77ff54401ccee3cb4b1aba36a71131f8 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    181,
 /**/
     180,
 /**/