]> granicus.if.org Git - vim/commitdiff
patch 8.1.1776: text added with a job isn't displayed v8.1.1776
authorBram Moolenaar <Bram@vim.org>
Mon, 29 Jul 2019 20:10:23 +0000 (22:10 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 29 Jul 2019 20:10:23 +0000 (22:10 +0200)
Problem:    Text added with a job to another buffer isn't displayed.
Solution:   Update topline after adding a line. (closes #4745)

src/channel.c
src/testdir/check.vim
src/testdir/dumps/Test_job_buffer_scroll_1.dump [new file with mode: 0644]
src/testdir/test_channel.vim
src/version.c

index 5d1b83aafa9748ca395a04f5cf2662b7b3404ea9..6351c892c3c16784e7691738606ed30a78b511c5 100644 (file)
@@ -2537,19 +2537,26 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
 
        FOR_ALL_WINDOWS(wp)
        {
-           if (wp->w_buffer == buffer
-                   && (save_write_to
-                       ? wp->w_cursor.lnum == lnum + 1
-                       : (wp->w_cursor.lnum == lnum
-                           && wp->w_cursor.col == 0)))
+           if (wp->w_buffer == buffer)
            {
-               ++wp->w_cursor.lnum;
-               save_curwin = curwin;
-               curwin = wp;
-               curbuf = curwin->w_buffer;
-               scroll_cursor_bot(0, FALSE);
-               curwin = save_curwin;
-               curbuf = curwin->w_buffer;
+               int move_cursor = save_write_to
+                           ? wp->w_cursor.lnum == lnum + 1
+                           : (wp->w_cursor.lnum == lnum
+                               && wp->w_cursor.col == 0);
+
+               // If the cursor is at or above the new line, move it one line
+               // down.  If the topline is outdated update it now.
+               if (move_cursor || wp->w_topline > buffer->b_ml.ml_line_count)
+               {
+                   if (move_cursor)
+                       ++wp->w_cursor.lnum;
+                   save_curwin = curwin;
+                   curwin = wp;
+                   curbuf = curwin->w_buffer;
+                   scroll_cursor_bot(0, FALSE);
+                   curwin = save_curwin;
+                   curbuf = curwin->w_buffer;
+               }
            }
        }
        redraw_buf_and_status_later(buffer, VALID);
index 7f37f1c96ee497b03e0d7954a5ed7ed8e055f729..48dbd85396f9074767fe55df8d6387779bd394a3 100644 (file)
@@ -21,3 +21,19 @@ func CheckFunction(name)
     throw 'Skipped: ' .. a:name .. ' function missing'
   endif
 endfunc
+
+" Command to check for running on MS-Windows
+command CheckMSWindows call CheckMSWindows()
+func CheckMSWindows()
+  if !has('win32')
+    throw 'Skipped: only works on MS-Windows'
+  endif
+endfunc
+
+" Command to check for running on Unix
+command CheckUnix call CheckUnix()
+func CheckUnix()
+  if !has('unix')
+    throw 'Skipped: only works on Unix'
+  endif
+endfunc
diff --git a/src/testdir/dumps/Test_job_buffer_scroll_1.dump b/src/testdir/dumps/Test_job_buffer_scroll_1.dump
new file mode 100644 (file)
index 0000000..11abe60
--- /dev/null
@@ -0,0 +1,10 @@
+|s+0&#ffffff0|o|m|e|t|e|x|t| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|X+1#0000000&|s|c|r|o|l@1|b|u|f@1|e|r| |[|+|]| @39|1|,|1| @11|A|l@1
+> +0&&@74
+|~+0#4040ff13&| @73
+|~| @73
+|[+3#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+|-+0&&@1|N|o| |l|i|n|e|s| |i|n| |b|u|f@1|e|r|-@1| @52
index 982a0459a156cff9328d0f4df493a60e59cb5764..62eaa2089c8fe241fd09ab3fac30fb23dcdffd0c 100644 (file)
@@ -1,10 +1,10 @@
 " Test for channel functions.
 
-if !has('channel')
-  throw 'Skipped: channel feature missing'
-endif
+source check.vim
+CheckFeature channel
 
 source shared.vim
+source screendump.vim
 
 let s:python = PythonProg()
 if s:python == ''
@@ -1125,6 +1125,35 @@ func Test_pipe_io_one_buffer()
   endtry
 endfunc
 
+func Test_write_to_buffer_and_scroll()
+  CheckFeature job
+  if !CanRunVimInTerminal()
+    throw 'Skipped: cannot make screendumps'
+  endif
+  let lines =<< trim END
+      new Xscrollbuffer
+      call setline(1, range(1, 200))
+      $
+      redraw
+      wincmd w
+      call deletebufline('Xscrollbuffer', 1, '$')
+      if has('win32')
+       let cmd = ['cmd', '/c', 'echo sometext']
+      else
+       let cmd = [&shell, &shellcmdflag, 'echo sometext']
+      endif
+      call job_start(cmd, #{out_io: 'buffer', out_name: 'Xscrollbuffer'})
+  END
+  call writefile(lines, 'XtestBufferScroll')
+  let buf = RunVimInTerminal('-S XtestBufferScroll', #{rows: 10})
+  sleep 500m
+  call VerifyScreenDump(buf, 'Test_job_buffer_scroll_1', {})
+
+  " clean up
+  call StopVimInTerminal(buf)
+  call delete('XtestBufferScroll')
+endfunc
+
 func Test_pipe_null()
   if !has('job')
     return
@@ -1804,9 +1833,8 @@ func Test_read_from_terminated_job()
 endfunc
 
 func Test_job_start_windows()
-  if !has('job') || !has('win32')
-    return
-  endif
+  CheckFeature job
+  CheckMSWindows
 
   " Check that backslash in $COMSPEC is handled properly.
   let g:echostr = ''
@@ -1820,9 +1848,7 @@ func Test_job_start_windows()
 endfunc
 
 func Test_env()
-  if !has('job')
-    return
-  endif
+  CheckFeature job
 
   let g:envstr = ''
   if has('win32')
@@ -1837,9 +1863,7 @@ func Test_env()
 endfunc
 
 func Test_cwd()
-  if !has('job')
-    return
-  endif
+  CheckFeature job
 
   let g:envstr = ''
   if has('win32')
@@ -1901,9 +1925,7 @@ func s:test_list_args(cmd, out, remove_lf)
 endfunc
 
 func Test_list_args()
-  if !has('job')
-    return
-  endif
+  CheckFeature job
 
   call s:test_list_args('import sys;sys.stdout.write("hello world")', "hello world", 0)
   call s:test_list_args('import sys;sys.stdout.write("hello\nworld")', "hello\nworld", 0)
@@ -1956,9 +1978,8 @@ func Test_keep_pty_open()
 endfunc
 
 func Test_job_start_in_timer()
-  if !has('job') || !has('timers')
-    return
-  endif
+  CheckFeature job
+  CheckFeature timers
 
   func OutCb(chan, msg)
     let g:val += 1
@@ -2017,9 +2038,8 @@ func Test_raw_large_data()
 endfunc
 
 func Test_no_hang_windows()
-  if !has('job') || !has('win32')
-    return
-  endif
+  CheckFeature job
+  CheckMSWindows
 
   try
     let job = job_start(s:python . " test_channel_pipe.py busy",
@@ -2055,9 +2075,8 @@ func Test_job_exitval_and_termsig()
 endfunc
 
 func Test_job_tty_in_out()
-  if !has('job') || !has('unix')
-    return
-  endif
+  CheckFeature job
+  CheckUnix
 
   call writefile(['test'], 'Xtestin')
   let in_opts = [{},
index 1043275a78f7c2464b309b36198ba8d3e2f51060..5b025117a96db0f75f7343cf83a584359a2ccf6a 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1776,
 /**/
     1775,
 /**/